بتل کد Battle Codeدارد باز می‌شود…

جواب «1 of 3 Done» چالش 4 از جلسه‌ی 7

سؤال

زیر لیست، متن count بگوید چند کار انجام شده، مثل 1 of 3 done. بعد از هر ضربه هم درست بماند.

راهنما

در show_list قبل از for: done = 0. در for: if t["done"]: done = done + 1. آخر: count.value = f"{done} of {len(todos)} done".

یک جواب درست

import app

todos = [
    {"text": "Feed the cat", "done": False},
    {"text": "Read a book", "done": True},
    {"text": "Tidy my desk", "done": False},
]

def show_list():
    items.clear()
    done = 0
    for t in todos:
        items.add(t["text"], done=t["done"])
        if t["done"]:
            done = done + 1
    count.value = f"{done} of {len(todos)} done"

def toggle(i):
    todos[i]["done"] = not todos[i]["done"]
    show_list()

app.title("My Tasks")
items = app.list()
items.on_tap(toggle)
count = app.text("")
show_list()
app.run()

اول خودت امتحان کن؛ جواب‌های دیگر هم قبول است. برگرد و خودت حلش کن