Skip to content

Commit ea46f2c

Browse files
authored
Merge pull request sumanth-0#707 from DevNexis/feature/issue-614-multilingual-flashcards
Add Multilingual Flashcards - Fixes sumanth-0#614
2 parents f67021a + 1435f2d commit ea46f2c

File tree

2 files changed

+169
-0
lines changed

2 files changed

+169
-0
lines changed
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
# Multilingual Flashcards
2+
3+
## Description
4+
An interactive language learning tool that helps users practice vocabulary in Spanish, French, and German through flashcard-style questions.
5+
6+
## Features
7+
- **3 Languages**: Practice Spanish, French, and German vocabulary
8+
- **Interactive CLI**: User-friendly command-line interface with emoji indicators
9+
- **Multiple Practice Modes**:
10+
- Practice individual languages
11+
- Practice all languages together
12+
- **Progress Tracking**: View statistics including total questions, correct answers, and accuracy percentage
13+
- **Random Questions**: Questions are shuffled for better learning
14+
15+
## Requirements
16+
- Python 3.6 or higher
17+
- No external dependencies required (uses only standard library)
18+
19+
## Installation
20+
1. Clone the repository
21+
2. Navigate to the snippet directory:
22+
```bash
23+
cd snippets/multilingual_flashcards
24+
```
25+
26+
## Usage
27+
Run the program:
28+
```bash
29+
python flashcards.py
30+
```
31+
32+
Follow the on-screen menu to:
33+
1. Select a language to practice (Spanish, French, or German)
34+
2. Practice all languages together
35+
3. View your learning statistics
36+
4. Exit the program
37+
38+
## Sample Vocabulary
39+
- **Spanish**: hola, gracias, adiós, agua, casa, libro, gato
40+
- **French**: bonjour, merci, au revoir, eau, maison, livre, chat
41+
- **German**: hallo, danke, auf wiedersehen, wasser, haus, buch, katze
42+
43+
## Example Output
44+
```
45+
==================================================
46+
🌍 MULTILINGUAL FLASHCARD LEARNING SYSTEM 🌍
47+
==================================================
48+
49+
Available Languages:
50+
1. Spanish (7 words)
51+
2. French (7 words)
52+
3. German (7 words)
53+
4. Practice All Languages
54+
5. View Statistics
55+
6. Exit
56+
57+
Select an option: 1
58+
59+
📚 Starting Spanish practice (5 questions)
60+
61+
Question 1/5: Translate 'hola' to English
62+
Your answer: hello
63+
✅ Correct!
64+
```
65+
66+
## Author
67+
Created for issue #614 - Make Multilingual Flashcards
68+
69+
## License
70+
Part of the 100LinesOfPythonCode project
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
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

Comments
 (0)