بتل کد 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).

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):
    return 0, []


# ---- 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)

راهنما و جواب این چالش · برگشت به درس جلسه‌ی 48: پروژه‌ی نهایی ۳: ارائه · چالش بعدی: Step 3: The Honesty Label

بیشتر بخوان: تابع در پایتون: آموزش def، پارامتر و return با مثال