-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
27 lines (22 loc) · 749 Bytes
/
main.py
File metadata and controls
27 lines (22 loc) · 749 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
import questions
import random
while True:
current_question = random.choice(questions.questions)
print(current_question['question'])
random.shuffle(current_question['answers'])
answers = current_question['answers']
for answer in range(len(answers)):
print(f"{answer+1}. {answers[answer]}")
try:
selected_answer = int(input("Enter your answer: "))
except ValueError:
print("Error: invalid number")
break
try:
if answers[selected_answer - 1] == current_question['correct']:
print("You answered correctly!")
else:
print("Your answer wasn't correct. (womp womp)")
except IndexError:
print("Error: invalid answer")
break