1
+ # Simple quiz program
2
+ # ----------------------------------------------------------------
3
+ def create_quiz ():
4
+
5
+ correct_answer = 0
6
+ guesses = []
7
+ question_number = 1
8
+ for key in Questions :
9
+ print ('----------------------------------------------------------------' )
10
+ print (key )
11
+ for i in Options [question_number - 1 ]:
12
+ print (i )
13
+ guess = input ('Enter a correct answer (A, B, C, or D): ' ).upper ()
14
+
15
+ guesses .append (guess )
16
+
17
+ correct_answer += check_answer (Questions .get (key ), guess )
18
+ question_number += 1
19
+
20
+ display_scores (correct_answer , guesses )
21
+
22
+ # ----------------------------------------------------------------
23
+ def display_scores (correct_answers , guesses ):
24
+ print ('-------------------------------------------------------' )
25
+ print ("RESULTS:" )
26
+ print ('-------------------------------------------------------' )
27
+
28
+ print ('Answers:' , end = ' ' )
29
+ for i in Questions :
30
+ print (Questions .get (i ), end = ' ' )
31
+ print ()
32
+
33
+ print ('Guesses:' , end = ' ' )
34
+ for i in guesses :
35
+ print (i , end = ' ' )
36
+ print ()
37
+
38
+ scores = int ((correct_answers / len (Questions )) * 100 )
39
+ print ("Scores: " + str (scores ) + '%' )
40
+
41
+ # ----------------------------------------------------------------
42
+ def check_answer (answer , guess ):
43
+ print ('----------------------------------------------------------------' )
44
+ if answer == guess :
45
+ print ("CORRECT" )
46
+ return 1
47
+ else :
48
+ print ("WRONG" )
49
+ return 0
50
+ # ----------------------------------------------------------------
51
+ def play_again ():
52
+ print ('----------------------------------------------------------------' )
53
+ again = input ("Do you want to play again (yes or no)?: " ).upper ()
54
+ if again == 'YES' :
55
+ create_quiz ()
56
+ return True
57
+ else :
58
+ print ("Byeeeeeeeeeee...." )
59
+ return False
60
+ # ----------------------------------------------------------------
61
+ Questions = {
62
+ '1. What is the largest living bird?' : 'B' ,
63
+ '2. What is the largest part of the body?' : 'B' ,
64
+ "3. Which part of thr body don't sleep?" : 'A' ,
65
+ "4. What makes plant food?" : 'C' ,
66
+ "5. Which planet is known as the red plant?" : 'D' ,
67
+ "6. How many legs does a spider has?" : 'D' ,
68
+ }
69
+ Options = [
70
+ ["A. Eagle" , "B. Ostrich" , "C. Falcon" , "D. Pelican" ],
71
+ ["A. Heart" , "B. Skin" , "C. Spine" , "D. Head" ],
72
+ ["A. Heart" , "B. Kidney" , "C. Brain" , "D. Liver" ],
73
+ ["A. Root" , "B. Stem" , "C. Leaf" , "D. Branches" ],
74
+ ["A. Earth" , "B. Jupiter" , "C. Saturn" , "D. Mars" ],
75
+ ["A. six" , "B. nine" , "C. seven" , "D. eight" ]
76
+ ]
77
+
78
+ create_quiz ()
79
+
80
+ while play_again ():
81
+ create_quiz ()
0 commit comments