جواب «Not Twice» چالش 7 از جلسهی 6
سؤال
یک کار نباید دو بار در لیست بیاید. اگر متن تمیزشده از قبل در todos بود، پیام Already in the list را نشان بده و اضافه نکن. " Read " هم با Read یکی است.
راهنما
بعد از چک خالی بودن (و بعد از strip!) بنویس if text in todos: و زیرش app.toast("Already in the list") و return.
یک جواب درست
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
if text in todos:
app.toast("Already in the list")
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()
اول خودت امتحان کن؛ جوابهای دیگر هم قبول است. برگرد و خودت حلش کن