Check the Plan چالش 3 از جلسهی 46، متوسط
check_plan(plan) لیست مشکلها را برگرداند: برای هر کلید REQUIRED که نیست یا خالی است ("" یا [])، missing + کلید؛ و اگر goal هست ولی هیچ رقمی ندارد، the goal needs a number. خروجی test:plan OK['missing sessions', 'the goal needs a number']['missing path', 'missing user', 'missing does', 'missing sessions', 'missing goal']
REQUIRED = ["path", "user", "does", "sessions", "goal"]
def check_plan(plan):
problems = []
return problems
# ---- test (do not change) ----
good = {"path": "B", "user": "kids in my class", "does": "answers questions from our science handout",
"sessions": [42, 44, 45], "goal": "8 of 10 test questions right"}
vague = {"path": "A", "user": "everyone", "does": "a fun game", "sessions": [], "goal": "it should be cool"}
empty = {}
for plan in [good, vague, empty]:
problems = check_plan(plan)
if len(problems) == 0:
print("plan OK")
else:
print(problems)
راهنما و جواب این چالش · برگشت به درس جلسهی 46: پروژهی نهایی ۱: نقشه · چالش بعدی: Will the Quota Last?
بیشتر بخوان: تابع در پایتون: آموزش def، پارامتر و return با مثال