待办清单里,做完的事前面写着 [x],没做完的写着 [ ]。写 todo_progress(tasks),返回像 "2/5" 这样的字符串:做完几项 / 一共几项。空清单返回 "0/0"。
todo_progress(["[x] feed the cat", "[ ] tidy desk", "[x] water plants"])→'2/3'todo_progress([])→'0/0'def todo_progress(tasks):
done = 0
for task in tasks:
# 在这里写:以 "[x]" 开头,done 就加 1
pass
return f"{done}/{len(tasks)}"
写好了先点「运行」试试示例,没问题再点「提交」。