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

جواب «Template 5: Checklist Score» چالش 6 از جلسه‌ی 79

سؤال

الگو (چک‌لیستِ حریمِ خصوصی): QUESTIONS فهرستِ پرسش‌ها با جوابِ امن است و answers جواب‌های کاربر. برای هر پرسش [ok] two-factor on? یا [fix] location tags off? چاپ کن؛ جوابِ ناشناس (نه yes نه no) هم [fix] حساب می‌شود (شکستِ ایمن). در پایان score: 3/5 و توصیه: ۵ → excellent؛ ۳ یا ۴ → good, fix the rest this week؛ کمتر → start with two-factor today.

راهنما

ok = answers.get(q) == safe؛ هر چیزِ دیگر fix است. امتیاز را بشمار و با if/elif/else توصیه بده.

یک جواب درست

QUESTIONS = [
    ("two-factor on?", "yes"),
    ("location tags off?", "yes"),
    ("account private?", "yes"),
    ("contact sync off?", "yes"),
    ("same password reused?", "no"),
]
answers = {"two-factor on?": "yes", "location tags off?": "no", "account private?": "yes", "contact sync off?": "maybe", "same password reused?": "no"}
score = 0
for q, safe in QUESTIONS:
    if answers.get(q) == safe:
        score += 1
        print("[ok] " + q)
    else:
        print("[fix] " + q)
print("score: " + str(score) + "/" + str(len(QUESTIONS)))
if score == 5:
    print("excellent")
elif score >= 3:
    print("good, fix the rest this week")
else:
    print("start with two-factor today")

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