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

Key Words and Partial Credit چالش 3 از جلسه‌ی 76، متوسط

تابع keyword_score(reply, keywords) را بنویس که تعداد کلمه‌های کلیدی موجود در جواب (با حروف کوچک) را برگرداند. برای هر آزمون test <i>: <hits>/<n> = <percent>% و در آخر میانگین درصدها را (هر دو بدون اعشار) چاپ کن. خروجی:
test 1: 3/3 = 100%
test 2: 1/3 = 33%
test 3: 3/3 = 100%
test 4: 0/3 = 0%
average 58%

TESTS = [
    ("What is evaporation?", "Water turns into vapour when the Sun heats it.", ["vapour", "sun", "heat"]),
    ("What is condensation?", "Clouds form.", ["vapour", "cools", "clouds"]),
    ("What is precipitation?", "Rain or snow falls from heavy clouds.", ["rain", "snow", "heavy"]),
    ("What is transpiration?", "It is a type of rock.", ["plants", "leaves", "water"]),
]


def keyword_score(reply, keywords):
    return 0


percents = []
for i, (question, reply, keywords) in enumerate(TESTS, 1):
    hits = keyword_score(reply, keywords)
    print(f"test {i}: {hits}/{len(keywords)}")

راهنما و جواب این چالش · برگشت به درس جلسه‌ی 76: ارزیابی مدل · چالش بعدی: Right, Wrong, Hallucinated, Over-Cautious

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