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

جواب «Step 6: The Full Report» چالش 6 از جلسه‌ی 71

سؤال

همه را به هم وصل کن. تابعِ report(name, done, times) را بنویس: times دیکشنری‌ای است از شماره‌ی قدم به زمانِ انجامش. گزارش را این‌طور چاپ کن: خطِ اول INCIDENT REPORT: hacked account؛ بعد برای هر قدمِ انجام‌شده 09:40 [contain] change the password from a clean device و برای قدمِ انجام‌نشده --:-- [learn] write what happened and when (pending)؛ در پایان done 4 of 5 و اگر چیزی مانده بود next: [learn] write what happened and when. بعد report("hacked account", {1, 2, 3, 4}, {1: "09:40", 2: "09:41", 3: "09:55", 4: "10:10"}) را صدا بزن.

راهنما

در حلقه، اگر i in done زمان را از times[i] بردار؛ وگرنه --:-- و پسوندِ (pending). اولین قدمِ انجام‌نشده را در یک متغیر نگه دار تا در پایان چاپ کنی.

یک جواب درست

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 report(name, done, times):
    steps = PLAYBOOK[name]
    print("INCIDENT REPORT: " + name)
    pending = None
    for i, (stage, action) in enumerate(steps, 1):
        if i in done:
            print(times[i] + " [" + stage + "] " + action)
        else:
            print("--:-- [" + stage + "] " + action + " (pending)")
            if pending is None:
                pending = (stage, action)
    print("done " + str(len(done)) + " of " + str(len(steps)))
    if pending:
        print("next: [" + pending[0] + "] " + pending[1])

report("hacked account", {1, 2, 3, 4}, {1: "09:40", 2: "09:41", 3: "09:55", 4: "10:10"})

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