forked from prkhrv/Python-CLI-Quiz
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathquiz.py
34 lines (28 loc) · 1.3 KB
/
quiz.py
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
from simple_chalk import chalk
from time import sleep
def start_quiz(questions):
score = 0
for i in range(0, len(questions)):
print('--------------------------------------------------------')
print(f'Q{i+1}) {questions[i]["question"]}\n'); sleep(0.2)
for j in range(1, 5):
print(f"({j}) {questions[i]['option'+str(j)]:30}", end='\t'); sleep(0.1)
if not j%2: print()
try:
answer = int(input("\nEnter your option number: ")); sleep(0.2)
if not 0<answer<5:
print(chalk.yellow("Please enter a choice between 1 and 4\n")); sleep(0.4)
continue
except ValueError:
print(chalk.cyan('Invalid Choice\n')); sleep(0.4)
continue
print()
if(questions[i]["correct_answer"] == "option"+str(answer)):
print(chalk.green("Correct Answer!!!\n")); sleep(0.4)
score = score + 1
else:
correct_answer = questions[i]["correct_answer"]
print(chalk.red(f"Wrong!! The Correct Answer is {questions[i][correct_answer]}")); sleep(0.4)
print()
print('--------------------------------------------------------\n\n')
print(chalk.yellow(f"Your Score is {score}/{len(questions)}"))