-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQUIZ.py
More file actions
251 lines (158 loc) · 5.86 KB
/
Copy pathQUIZ.py
File metadata and controls
251 lines (158 loc) · 5.86 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
user_name = ""
user_pass = ""
login_success = False
score = 0
attempted = 0
correct_answers = 0
wrong_answers = 0
quiz_history = ""
while True:
print("\n========== SMART QUIZ CHALLENGE SYSTEM ==========")
print("1 → Register")
print("2 → Login")
print("3 → Start Quiz")
print("4 → View Score")
print("5 → Quiz History")
print("6 → Reset Score")
print("7 → Logout")
print("0 → Exit")
choice = int(input("\nEnter your choice: "))
match choice:
# REGISTER
case 1:
if user_name != "":
print("Account already registered!")
else:
user_name = input("Create Username: ").lower()
user_pass = input("Create Password: ")
print("Registration Successful!")
# LOGIN
case 2:
if login_success == True:
print("You are already logged in!")
elif user_name == "":
print("Please Register First!")
else:
attempts = 3
while attempts > 0:
login_name = input("Enter Username: ").lower()
login_pass = input("Enter Password: ")
if (user_name, user_pass) == (login_name, login_pass):
print("Login Successful!")
login_success = True
break
else:
attempts -= 1
print(f"Invalid Credentials")
print(f"{attempts} attempts left!")
if login_success == False:
print("Maximum login attempts reached!")
# START QUIZ
case 3:
if login_success == False:
print("Please Login and retry")
else:
print("\n========== QUIZ STARTED ==========")
# QUESTION 1
print("\nQ1. What is Duck Number?")
print("1. Number starting with zero")
print("2. Number containing zero")
print("3. Prime Number")
print("4. Palindrome Number")
ans1 = int(input("Enter option: "))
attempted += 1
if ans1 == 2:
print("Correct Answer!")
score += 1
correct_answers += 1
quiz_history += "\nQ1 Correct"
else:
print("Wrong Answer!")
wrong_answers += 1
quiz_history += "\nQ1 Wrong"
# QUESTION 2
print("\nQ2. What is Tech Number?")
print("1. Number divisible by 2")
print("2. Number having even digits")
print("3. Number whose split sum square equals original")
print("4. Prime Number")
ans2 = int(input("Enter option: "))
attempted += 1
if ans2 == 3:
print("Correct Answer!")
score += 1
correct_answers += 1
quiz_history += "\nQ2 Correct"
else:
print("Wrong Answer!")
wrong_answers += 1
quiz_history += "\nQ2 Wrong"
# QUESTION 3
print("\nQ3. Which loop is infinite?")
print("1. while True")
print("2. for")
print("3. if")
print("4. else")
ans3 = int(input("Enter option: "))
attempted += 1
if ans3 == 1:
print("Correct Answer!")
score += 1
correct_answers += 1
quiz_history += "\nQ3 Correct"
else:
print("Wrong Answer!")
wrong_answers += 1
quiz_history += "\nQ3 Wrong"
print("\nQuiz Completed!")
# VIEW SCORE
case 4:
if login_success == False:
print("Please Login and retry")
else:
print("\n========== SCORE BOARD ==========")
print(f"Questions Attempted : {attempted}")
print(f"Correct Answers : {correct_answers}")
print(f"Wrong Answers : {wrong_answers}")
print(f"Final Score : {score}")
if score >= 3:
print("Performance : Excellent")
elif score == 2:
print("Performance : Good")
else:
print("Performance : Needs Improvement")
# QUIZ HISTORY
case 5:
if login_success == False:
print("Please Login and retry")
else:
print("\n========== QUIZ HISTORY ==========")
if quiz_history == "":
print("No quiz attempted yet!")
else:
print(quiz_history)
# RESET SCORE
case 6:
if login_success == False:
print("Please Login and retry")
else:
score = 0
attempted = 0
correct_answers = 0
wrong_answers = 0
quiz_history = ""
print("Quiz score reset successfully!")
# LOGOUT
case 7:
if login_success == False:
print("You are already logged out!")
else:
login_success = False
print("Successfully Logged Out!")
# EXIT
case 0:
print("Thank You for Using Smart Quiz Challenge System")
break
# INVALID CHOICE
case _:
print("Invalid choice! Please try again.")