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

جواب «Step 3: The Honesty Label» چالش 3 از جلسه‌ی 48

سؤال

honesty_label(parts): هر بخش یک (part, who) است و who یکی از "ai"، "me"، "both". بخش‌ها را در دیکشنری groups جدا کن و چاپ کن:
AI wrote: the answers in the chat, the page colours
I wrote: the handout, words() and score(), the attack test
We wrote together: the safe calculator
written only by me: 50 %

راهنما

groups[who].append(part) و برای چاپ ", ".join(groups["ai"]).

یک جواب درست

def honesty_label(parts):
    groups = {"ai": [], "me": [], "both": []}
    for part, who in parts:
        groups[who].append(part)
    print("AI wrote:", ", ".join(groups["ai"]))
    print("I wrote:", ", ".join(groups["me"]))
    print("We wrote together:", ", ".join(groups["both"]))
    mine = len(groups["me"]) * 100 // len(parts)
    print("written only by me:", mine, "%")


# ---- test (do not change) ----
honesty_label([
    ("the handout", "me"),
    ("words() and score()", "me"),
    ("the safe calculator", "both"),
    ("the answers in the chat", "ai"),
    ("the attack test", "me"),
    ("the page colours", "ai"),
])

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