-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
36 lines (26 loc) · 1017 Bytes
/
Copy pathmain.py
File metadata and controls
36 lines (26 loc) · 1017 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
32
33
34
35
36
# main.py
from data import quiz
def run_quiz():
score = 0
total_questions = len(quiz)
for key in quiz:
# Retrieve the question and answer
question = quiz[key]["question"]
correct_answer = quiz[key]["answer"]
# Print the question and get the user's answer
user_answer = input(f"{question} ").strip()
# Check if the user's answer is correct (case-insensitive)
if user_answer.lower() == correct_answer.lower():
print("Correct!")
score += 1
else:
print(f"Wrong! The correct answer is {correct_answer}.")
# Display the current score
print(f"Current Score: {score}/{total_questions}")
# Display final results
print("\nQuiz Complete!")
print(f"Total Correct Answers: {score}/{total_questions}")
percentage = (score / total_questions) * 100
print(f"Percentage Correct: {percentage:.2f}%")
if __name__ == "__main__":
run_quiz()