|
| 1 | +#!/usr/bin/env python3 |
| 2 | +"""Multilingual Flashcard Learning System - Interactive language learning tool""" |
| 3 | +import random |
| 4 | +from typing import Dict |
| 5 | + |
| 6 | +class MultilingualFlashcards: |
| 7 | + def __init__(self): |
| 8 | + self.flashcards = { |
| 9 | + 'spanish': {'hola': 'hello', 'gracias': 'thank you', 'adiós': 'goodbye', 'agua': 'water', 'casa': 'house', 'libro': 'book', 'gato': 'cat'}, |
| 10 | + 'french': {'bonjour': 'hello', 'merci': 'thank you', 'au revoir': 'goodbye', 'eau': 'water', 'maison': 'house', 'livre': 'book', 'chat': 'cat'}, |
| 11 | + 'german': {'hallo': 'hello', 'danke': 'thank you', 'auf wiedersehen': 'goodbye', 'wasser': 'water', 'haus': 'house', 'buch': 'book', 'katze': 'cat'} |
| 12 | + } |
| 13 | + self.score = 0 |
| 14 | + self.total_questions = 0 |
| 15 | + |
| 16 | + def display_menu(self): |
| 17 | + """Display main menu""" |
| 18 | + print("\n" + "="*50) |
| 19 | + print("🌍 MULTILINGUAL FLASHCARD LEARNING SYSTEM 🌍") |
| 20 | + print("="*50 + "\n\nAvailable Languages:") |
| 21 | + for idx, lang in enumerate(self.flashcards.keys(), 1): |
| 22 | + print(f"{idx}. {lang.capitalize()} ({len(self.flashcards[lang])} words)") |
| 23 | + print(f"{len(self.flashcards) + 1}. Practice All Languages") |
| 24 | + print(f"{len(self.flashcards) + 2}. View Statistics") |
| 25 | + print(f"{len(self.flashcards) + 3}. Exit") |
| 26 | + |
| 27 | + def practice_language(self, language: str, num_questions: int = 5): |
| 28 | + """Practice flashcards for a specific language""" |
| 29 | + if language not in self.flashcards: |
| 30 | + print(f"❌ Language '{language}' not found!") |
| 31 | + return |
| 32 | + cards = list(self.flashcards[language].items()) |
| 33 | + random.shuffle(cards) |
| 34 | + print(f"\n📚 Starting {language.capitalize()} practice ({num_questions} questions)\n") |
| 35 | + for i, (foreign, english) in enumerate(cards[:num_questions], 1): |
| 36 | + print(f"Question {i}/{num_questions}: Translate '{foreign}' to English") |
| 37 | + answer = input("Your answer: ").strip().lower() |
| 38 | + self.total_questions += 1 |
| 39 | + if answer == english.lower(): |
| 40 | + print("✅ Correct!\n") |
| 41 | + self.score += 1 |
| 42 | + else: |
| 43 | + print(f"❌ Wrong! The correct answer is: {english}\n") |
| 44 | + |
| 45 | + def practice_all_languages(self, num_questions: int = 10): |
| 46 | + """Practice flashcards from all languages""" |
| 47 | + all_cards = [] |
| 48 | + for lang, cards in self.flashcards.items(): |
| 49 | + for foreign, english in cards.items(): |
| 50 | + all_cards.append((foreign, english, lang)) |
| 51 | + random.shuffle(all_cards) |
| 52 | + print(f"\n🌐 Practicing all languages ({num_questions} questions)\n") |
| 53 | + for i, (foreign, english, lang) in enumerate(all_cards[:num_questions], 1): |
| 54 | + print(f"Question {i}/{num_questions} [{lang.capitalize()}]: Translate '{foreign}'") |
| 55 | + answer = input("Your answer: ").strip().lower() |
| 56 | + self.total_questions += 1 |
| 57 | + if answer == english.lower(): |
| 58 | + print("✅ Correct!\n") |
| 59 | + self.score += 1 |
| 60 | + else: |
| 61 | + print(f"❌ Wrong! The correct answer is: {english}\n") |
| 62 | + |
| 63 | + def show_statistics(self): |
| 64 | + """Display learning statistics""" |
| 65 | + print("\n" + "="*50) |
| 66 | + print("📊 YOUR STATISTICS") |
| 67 | + print("="*50) |
| 68 | + print(f"Total Questions Answered: {self.total_questions}") |
| 69 | + print(f"Correct Answers: {self.score}") |
| 70 | + if self.total_questions > 0: |
| 71 | + accuracy = (self.score / self.total_questions) * 100 |
| 72 | + print(f"Accuracy: {accuracy:.1f}%") |
| 73 | + print("="*50) |
| 74 | + |
| 75 | + def run(self): |
| 76 | + """Main application loop""" |
| 77 | + while True: |
| 78 | + self.display_menu() |
| 79 | + choice = input("\nSelect an option: ").strip() |
| 80 | + if choice == '1': |
| 81 | + self.practice_language('spanish') |
| 82 | + elif choice == '2': |
| 83 | + self.practice_language('french') |
| 84 | + elif choice == '3': |
| 85 | + self.practice_language('german') |
| 86 | + elif choice == '4': |
| 87 | + self.practice_all_languages() |
| 88 | + elif choice == '5': |
| 89 | + self.show_statistics() |
| 90 | + elif choice == '6': |
| 91 | + print("\n👋 Thank you for practicing! Keep learning!") |
| 92 | + self.show_statistics() |
| 93 | + break |
| 94 | + else: |
| 95 | + print("\n❌ Invalid choice! Please try again.") |
| 96 | + |
| 97 | +if __name__ == "__main__": |
| 98 | + app = MultilingualFlashcards() |
| 99 | + app.run() |
0 commit comments