Not Twice چالش 7 از جلسهی 6، سخت
یک کار نباید دو بار در لیست بیاید. اگر متن تمیزشده از قبل در todos بود، پیام Already in the list را نشان بده و اضافه نکن. " Read " هم با Read یکی است.
import app
todos = []
def show_list():
items.clear()
for t in todos:
items.add(t)
count.value = f"Tasks: {len(todos)}"
def add():
text = box.value.strip()
if text == "":
app.toast("Write a task first")
return
todos.append(text)
box.value = ""
show_list()
app.title("My Tasks")
box = app.input("New task")
app.button("Add", add)
items = app.list()
count = app.text("Tasks: 0")
show_list()
app.run()
راهنما و جواب این چالش · برگشت به درس جلسهی 6: افزودن · چالش بعدی: Five Is Enough
بیشتر بخوان: تابع در پایتون: آموزش def، پارامتر و return با مثال