solution.py Python """Vocabulary Quiz — Bidirectional + Review Mode"""
import random
WORDS = {
"apple": "Apple", "book": "Book", "table": "Table", "door": "Door",
"water": "Water", "fire": "Fire", "tree": "Tree", "sky": "Sky",
"love": "Love", "time": "Time", "house": "House", "car": "Car",
}
def quiz(pairs, mode):
score = 0
wrong = []
for i, (en, ko) in enumerate(pairs, 1):
if mode == "en2ko":
q, a = en, ko
elif mode == "ko2en":
q, a = ko, en
else: # random
if random.random() < 0.5:
q, a = en, ko
else:
q, a = ko, en
ans = input(f"[{i}/{len(pairs)}] {q}? ").strip()
if ans == a:
print("✓ Correct")
score += 1
else:
print(f"✗ Wrong (Correct answer: {a})")
wrong.append((q, a))
return score, wrong
def main():
print("[Mode] 1. Eng→Kor 2. Kor→Eng 3. Random")
mode_map = {"1": "en2ko", "2": "ko2en", "3": "random"}
mode = mode_map.get(input("Select:").strip(), "en2ko")
pairs = random.sample(list(WORDS.items()), min(10, len(WORDS)))
score, wrong = quiz(pairs, mode)
print(f"Total score: {score} / {len(pairs)}")
if wrong and input("Review only wrong questions? (y/n):").strip().lower() == "y":
score2, _ = quiz(wrong, mode)
print(f"Review score: {score2} / {len(wrong)}")
if __name__ == "__main__":
main()