-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbonus15.py
More file actions
31 lines (24 loc) · 885 Bytes
/
Copy pathbonus15.py
File metadata and controls
31 lines (24 loc) · 885 Bytes
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
import json #From questions.json file
with open("questions.json", "r") as file:
content = file.read() # is string
data = json.loads(content) # is list
for question in data:
print(question["question_text"])
for index, alternative in enumerate(question["alternatives"]):
print(index + 1, "-", alternative)
user_choice = int(input("Enter your answer: "))
question["user_choice"] = user_choice
score = 0
for index, question in enumerate(data):
if question["user_choice"] == question["correct_answer"]:
score = score + 1
result = "Correct Answer"
else:
result = "Wrong Answer"
message = (
f"{index + 1} {result} - Your answer: {question['user_choice']}, "
f"Correct answer: {question['correct_answer']}"
)
print(message)
print(data)
print(score, "/", len(data))