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

جواب «Step 2: Accuracy from the Tests» چالش 2 از جلسه‌ی 48

سؤال

model_card آماده است. score_results(results) برای هر (question, expected, reply): اگر expected در reply بود right را زیاد کند، وگرنه question را به mistakes اضافه کند؛ آخر right, mistakes را برگرداند. خروجی test با 3 ['How many members?'] شروع می‌شود و بعد کارت مدل با Accuracy: 75 % (3 of 4).

راهنما

for question, expected, reply in results: و آخر return right, mistakes.

یک جواب درست

def model_card(name, data, right, total, mistakes):
    print("MODEL CARD:", name)
    print("Data:", data)
    print("Accuracy:", right * 100 // total, "%", "(" + str(right), "of", str(total) + ")")
    print("Where it goes wrong:")
    for m in mistakes:
        print("-", m)

def score_results(results):
    right = 0
    mistakes = []
    for question, expected, reply in results:
        if expected in reply:
            right += 1
        else:
            mistakes.append(question)
    return right, mistakes


# ---- test (do not change) ----
results = [
    ("When does the club meet?", "Tuesday", "Every Tuesday after school. [part 1]"),
    ("How many members?", "12", "The club meets every Tuesday. [part 1]"),
    ("Who waters the beds?", "Sprout", "The robot Sprout waters them. [part 3]"),
    ("Capital of France?", "I don't know", "I don't know. The handout does not say."),
]
right, mistakes = score_results(results)
print(right, mistakes)
model_card("Robo Garden Helper", "the Robo Garden handout", right, len(results), mistakes)

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