Böyle bir quiz sistemini kendim yazmak yerine ChatGPT'ye yazdırdığım için kendimi aptal hiss ediyorum.
print("Welcome to the Python Quiz!")
print("Choose the correct answer from the options (a, b, c, d). You only have one attempt.")
questions = [
{
"question": "What is the result of 3 + 4?",
"options": {
"a": "5",
"b": "6",
"c": "7",
"d": "8"
},
"answer": "c"
},
{
"question": "What is the value of x after the following code is executed? x = 5; x += 2;",
"options": {
"a": "5",
"b": "6",
"c": "7",
"d": "8"
},
"answer": "c"
}
]
correct_answers = 0
play_again = "yes"
while play_again == "yes":
for q in questions:
print(q["question"])
for opt in q["options"]:
print(f"{opt}. {q['options'][opt]}")
user_answer = input("Your answer: ")
if user_answer == q["answer"]:
print("Correct!")
correct_answers += 1
else:
print("Incorrect. Game over.")
play_again = input(f"You got {correct_answers} correct answers. Do you want to play again? (yes/no) ")
break
print("Thanks for playing!")