-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathquiz.py
35 lines (24 loc) · 847 Bytes
/
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
35
# The simple quiz with questions in a json file
import json
points = 0
def show_questions(quest):
global points
print()
print(quest['question'])
print('a', quest['a'])
print('b', quest['b'])
print('c', quest['c'])
print('d', quest['d'])
print()
answer = input('Which answer do you choose: ')
if answer == quest['correct_answer']:
points += 1
print(f"That's the correct, you already have {points} points, bravo!")
else:
print("Unfortunately, that's the wrong answer, the correct answer is:", quest['correct_answer'])
with open('quiz_questions.json') as json_file:
questions = json.load(json_file)
for i in range(0, len(questions)):
show_questions(questions[i])
print()
print(f"Game over! You scored {points} points.")