جواب «Track A: A Fair Test Set for the Bot» چالش 3 از جلسهی 77
سؤال
مسیر الف. قبل از ساختن ربات، آزمونش را بنویس و بررسی کن منصفانه است. تابع audit(tests, notes) را بنویس که مشکلها را به این ترتیب چاپ کند: ۱) هر سؤال تکراری: duplicate: <question>؛ ۲) هر کلمهی کلیدی که در جزوه (با حروف کوچک) نیست: not in notes: <keyword> (آزمون ناعادلانه است)؛ ۳) اگر سؤال بیجواب (None) کمتر از ۲ تاست: need at least 2 unanswerable (have <n>). اگر مشکلی نبود test set OK. خروجی:duplicate: What is evaporation?not in notes: photosynthneed at least 2 unanswerable (have 1)
راهنما
یک set به اسم seen برای سؤالها نگه دار. low = notes.lower() و if key is not None and key not in low. تعداد Noneها: sum(1 for q, k in tests if k is None). یک متغیر problems = 0 بگذار تا آخر بدانی OK چاپ کنی یا نه.
یک جواب درست
NOTES = '''Evaporation is when the sun heats water and it turns into vapour.
Condensation is when vapour cools and forms clouds.
Precipitation is rain or snow falling from heavy clouds.
Transpiration is when plants lose water through their leaves.'''
TESTS = [ # (question, key word, or None when the notes have no answer)
("What is evaporation?", "vapour"),
("What is condensation?", "clouds"),
("What is evaporation?", "evaporation"),
("How do plants lose water?", "leaves"),
("What do plants make with light?", "photosynth"),
("Who was the first head teacher of our school?", None),
]
def audit(tests, notes):
problems = 0
seen = set()
for question, key in tests:
if question in seen:
print("duplicate:", question)
problems += 1
seen.add(question)
low = notes.lower()
for question, key in tests:
if key is not None and key not in low:
print("not in notes:", key)
problems += 1
unanswerable = sum(1 for q, k in tests if k is None)
if unanswerable < 2:
print(f"need at least 2 unanswerable (have {unanswerable})")
problems += 1
if problems == 0:
print("test set OK")
audit(TESTS, NOTES)
اول خودت امتحان کن؛ جوابهای دیگر هم قبول است. برگرد و خودت حلش کن