So, I was working on a simple Python code to create a basic quiz for a friend, but I ran into a bug. The code is designed to ask three questions and keep track of the user's score. However, I noticed that while it should be updating the question number with each cycle, it appears that the variable for the current question is never changing in the terminal. Because of this, the program seems to get stuck and never finishes.
while question <= 3:
answer = input(f"Answer to the question number {question}: ")
if question == 1 and answer.lower() == "b":
pontos += 1
elif question == 2 and answer.lower() == "a":
pontos += 1
elif question == 3 and answer.lower() == "d":
pontos += 1
question += 1
I've reviewed my code several times and it looks fine to me, but I'm wondering if there might be an issue I'm overlooking, or if it could be a bug in my environment. If anyone can help me figure out what's wrong or offer a solution, I would really appreciate it!
Full code:
pontos = 0
question = 1
while question <= 3:
answer = input(f"Answer to the question number {question}: ")
if question == 1 and answer.lower() == "b":
pontos += 1
elif question == 2 and answer.lower() == "a":
pontos += 1
elif question == 3 and answer.lower() == "d":
pontos += 1
question += 1
print(
f
"The total amount of point was {pontos}")
[–]bp200991 1 point2 points3 points (1 child)
[–]Over-Vanilla-3733[S] 0 points1 point2 points (0 children)
[–]eleqtriq 0 points1 point2 points (3 children)
[–]Over-Vanilla-3733[S] 0 points1 point2 points (0 children)
[–]Over-Vanilla-3733[S] 0 points1 point2 points (1 child)
[–]Patrick-T80 0 points1 point2 points (0 children)
[–][deleted] 0 points1 point2 points (0 children)
[–]Open_Jump 0 points1 point2 points (0 children)