Skip to content

Commit 2263366

Browse files
committed
main funtion has been added
1 parent a75df7b commit 2263366

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,58 @@
1+
import random
12
class Flashcard:
23
def __init__(self, question, answer):
34
self.question = question
45
self.answer = answer
56

7+
class FlashcardQuizzer:
8+
def __init__(self):
9+
self.flashcards = []
10+
self.score = 0
11+
12+
def add_flashcard(self, question, answer):
13+
self.flashcards.append(Flashcard(question, answer))
14+
15+
def quiz(self):
16+
if not self.flashcards:
17+
print("No flashcards available.")
18+
return
19+
20+
random.shuffle(self.flashcards)
21+
self.score = 0
22+
23+
for flashcard in self.flashcards:
24+
user_answer = input(f"Q: {flashcard.question} ")
25+
if user_answer.strip().lower() == flashcard.answer.strip().lower():
26+
print("Correct!")
27+
self.score += 1
28+
else:
29+
print(f"Wrong! The correct answer was: {flashcard.answer}")
30+
31+
print(f"Quiz finished! Your score: {self.score}/{len(self.flashcards)}")
32+
33+
34+
def main():
35+
quizzer = FlashcardQuizzer()
36+
37+
while True:
38+
print("\nFlashcard Quizzer")
39+
print("1. Add Flashcard")
40+
print("2. Start Quiz")
41+
print("3. Exit")
42+
choice = input("Choose an option: ")
43+
44+
if choice == '1':
45+
question = input("Enter the question: ")
46+
answer = input("Enter the answer: ")
47+
quizzer.add_flashcard(question, answer)
48+
print("Flashcard added!")
49+
elif choice == '2':
50+
quizzer.quiz()
51+
elif choice == '3':
52+
print("Goodbye!")
53+
break
54+
else:
55+
print("Invalid choice. Please try again.")
56+
57+
if __name__ == "__main__":
58+
main()

0 commit comments

Comments
 (0)