|
2 | 2 | # List of questions for quiz
|
3 | 3 |
|
4 | 4 | questions =[
|
5 |
| - |
6 | 5 | 'who is the developer of Python Language',
|
7 |
| - |
8 | 6 | 'when did india gets independence',
|
9 |
| - |
10 | 7 | 'what is the Indian currency',
|
11 |
| - |
12 | 8 | 'Who is World first cloned human baby',
|
13 |
| - |
14 | 9 | 'who is the founder of Hinduism'
|
15 |
| - |
16 | 10 | ]
|
17 | 11 |
|
18 |
| - |
19 |
| - |
20 | 12 | # list of answers for above questions
|
21 | 13 |
|
22 |
| - |
23 |
| - |
24 | 14 | answers = [
|
25 |
| - |
26 | 15 | 'Guido Van',
|
27 |
| - |
28 | 16 | '1947',
|
29 |
| - |
30 | 17 | 'INR',
|
31 |
| - |
32 | 18 | 'Eve',
|
33 |
| - |
34 | 19 | 'No Specific'
|
35 |
| - |
36 | 20 | ]
|
37 | 21 |
|
38 |
| - |
39 |
| - |
40 | 22 | # List of options for above questions
|
41 | 23 |
|
42 |
| - |
43 |
| - |
44 | 24 | options= [
|
45 |
| - |
46 | 25 | ['Dennis Ritchie','Alan Frank','Guido Van','Albert'],
|
47 |
| - |
48 | 26 | ['1947','1995','1950','1957'],
|
49 |
| - |
50 | 27 | ['DOLLARS','YEN','EURO','INR'],
|
51 |
| - |
52 | 28 | ['Erik','Maria','Sophie','Eve'],
|
53 |
| - |
54 | 29 | ['Mahavira Swami','Mahatma Buddha','No Specific','Prophet Mohammed']
|
55 |
| - |
56 | 30 | ]
|
57 | 31 |
|
58 |
| - |
59 |
| - |
60 | 32 | # Quiz Game | Designed by Ishita
|
61 | 33 |
|
62 |
| - |
63 |
| - |
64 | 34 | # Defining function for game playing
|
65 | 35 |
|
66 |
| - |
67 |
| - |
68 | 36 | def play_game(username,questions,answers,options):
|
69 |
| - |
70 | 37 | print("Hello,", username, "welcome to the QUIZ game")
|
71 |
| - |
72 | 38 | print("All the Best for the Game :>")
|
73 |
| - |
74 | 39 | score = 0
|
75 |
| - |
76 | 40 | for i in range(5):
|
77 |
| - |
78 | 41 | current_questions = questions[i]
|
79 |
| - |
80 | 42 | # print(questions[i])
|
81 |
| - |
82 | 43 | correct_answer = answers[i]
|
83 |
| - |
84 | 44 | current_question_options = options[i]
|
85 |
| - |
86 | 45 | print("Questions:" ,current_questions)
|
87 |
| - |
88 | 46 | for index,each_options in enumerate(current_question_options):
|
89 |
| - |
90 | 47 | print(index+1,") ",each_options,sep='')
|
91 |
| - |
92 | 48 | user_answer_index = int(input("Please enter your choice(1,2,3,4): "))
|
93 |
| - |
94 | 49 | user_answer = current_question_options[user_answer_index-1]
|
95 |
| - |
96 | 50 | if user_answer== correct_answer:
|
97 |
| - |
98 | 51 | print("correct answer")
|
99 |
| - |
100 | 52 | score = score +100
|
101 |
| - |
102 | 53 | else:
|
103 |
| - |
104 | 54 | print("wrong answer")
|
105 |
| - |
106 | 55 | break
|
107 |
| - |
108 | 56 | print("Your final score is", score)
|
109 |
| - |
110 | 57 | return username,score
|
111 |
| - |
112 |
| - |
113 |
| - |
| 58 | + |
114 | 59 | # Defining function for viewing the score
|
115 | 60 |
|
116 |
| - |
117 |
| - |
118 | 61 | def view_scores(names_and_scores):
|
119 |
| - |
120 | 62 | for name,score in names_and_scores.items():
|
121 |
| - |
122 | 63 | print(name,"has scored",score)
|
123 |
| - |
124 |
| - |
125 |
| - |
126 |
| -# Defining the function for start of the game |
127 |
| - |
128 | 64 |
|
| 65 | +# Defining the function for start of the score |
129 | 66 |
|
130 | 67 | def quiz(questions,answers,options):
|
131 |
| - |
132 |
| - |
133 |
| - |
134 | 68 | names_and_scores = {}
|
135 |
| - |
136 | 69 | while True:
|
137 |
| - |
138 | 70 | print("Welcome to the quiz game")
|
139 |
| - |
140 | 71 | print("1) Play\n2) View Scores\n3) Exit")
|
141 |
| - |
142 | 72 | choice=int(input("Please enter your choice: "))
|
143 |
| - |
144 | 73 | if choice == 1:
|
145 |
| - |
146 | 74 | username =(input("Please enter your name: "))
|
147 |
| - |
148 | 75 | username,score = play_game(username,questions,answers,options)
|
149 |
| - |
150 | 76 | names_and_scores[username] = score
|
151 |
| - |
152 |
| - |
153 |
| - |
154 |
| - |
155 |
| - |
156 | 77 | elif choice ==2:
|
157 |
| - |
158 |
| - view_scores(names_and_scores) |
159 |
| - |
160 |
| - |
161 |
| - |
| 78 | + view_scores(names_and_scores) |
162 | 79 | elif choice ==3:
|
163 |
| - |
164 | 80 | break
|
165 |
| - |
166 |
| - |
167 |
| - |
168 | 81 | else :
|
| 82 | + print("Your choice is not correct") |
169 | 83 |
|
170 |
| - print("Your choice is not correct") |
171 |
| - |
172 |
| - |
173 |
| - |
174 |
| -# Program execution starts from here |
175 |
| - |
176 |
| - |
| 84 | +# Program execution starts from here |
177 | 85 |
|
178 | 86 | quiz(questions,answers,options)
|
0 commit comments