2. 写第一个脚本(sol.py):import solarasentence = solara.reactive("Solara makes our team more productive.")word_limit = solara.reactive(10)@solara.componentdefPage(): word_count = len(sentence.value.split()) solara.SliderInt("Word limit", value=word_limit, min=2, max=20) solara.InputText(label="Your sentence", value=sentence, continuous_update=True)if word_count >= int(word_limit.value): solara.Error(f"With {word_count} words, you passed the word limit of {word_limit.value}.")elif word_count >= int(0.8 * word_limit.value): solara.Warning(f"With {word_count} words, you are close to the word limit of {word_limit.value}.")else: solara.Success("Great short writing!")Page()
把上面保存成 sol.py,或者直接放到 Notebook cell 里执行。