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

جواب «Step 4: Next Action» چالش 4 از جلسه‌ی 71

سؤال

تابعِ next_action(name, done) را بنویس که اولین قدمِ انجام‌نشده را به شکلِ next: [recover] turn on 2FA برگرداند، و اگر همه انجام شده بود all done - now update the playbook برگرداند. نتیجه را برای done = {1, 2} و برای done = {1, 2, 3, 4, 5} چاپ کن.

راهنما

در حلقه، اولین i not in done را با return برگردان؛ return بعدِ حلقه برای حالتِ «همه انجام شده» است.

یک جواب درست

PLAYBOOK = {
    "hacked account": [
        ("contain", "change the password from a clean device"),
        ("contain", "sign out all devices"),
        ("recover", "turn on 2FA"),
        ("recover", "tell friends to ignore messages from you"),
        ("learn", "write what happened and when"),
    ],
}

def next_action(name, done):
    for i, (stage, action) in enumerate(PLAYBOOK[name], 1):
        if i not in done:
            return "next: [" + stage + "] " + action
    return "all done - now update the playbook"

print(next_action("hacked account", {1, 2}))
print(next_action("hacked account", {1, 2, 3, 4, 5}))

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