جواب «Checked Quiz Questions» چالش 6 از جلسهی 9
سؤال
برای بازی مسابقهی جلسهی ۱۲، هوش مصنوعی پنج سؤال و جواب پیشنهاد داده (candidates). فقط آنهایی را نگه دار که جوابشان با book یکی است (اگر سؤال در کتاب نیست، book.get(q) جواب None میدهد و نگهش نمیداری). اول چاپ کن kept 3 of 5، بعد هر سؤال نگهداشته را در یک خط به شکل سؤال = جواب.
راهنما
for q, a in candidates: و if book.get(q) == a: kept.append((q, a)). بعد print("kept", len(kept), "of", len(candidates)).
یک جواب درست
book = {
"Is there a Nobel Prize in mathematics?": "no",
"Should you share your password with a chat bot?": "no",
"Can AI make up facts?": "yes",
}
candidates = [
("Is there a Nobel Prize in mathematics?", "yes"),
("Should you share your password with a chat bot?", "no"),
("Can AI make up facts?", "yes"),
("Does AI always tell the truth?", "yes"),
("Is there a Nobel Prize in mathematics?", "no"),
]
kept = []
for q, a in candidates:
if book.get(q) == a:
kept.append((q, a))
print("kept", len(kept), "of", len(candidates))
for q, a in kept:
print(q, "=", a)
اول خودت امتحان کن؛ جوابهای دیگر هم قبول است. برگرد و خودت حلش کن