File tree 1 file changed +53
-0
lines changed
1 file changed +53
-0
lines changed Original file line number Diff line number Diff line change
1
+ import random
1
2
class Flashcard :
2
3
def __init__ (self , question , answer ):
3
4
self .question = question
4
5
self .answer = answer
5
6
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 ("\n Flashcard 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 ()
You can’t perform that action at this time.
0 commit comments