Skip to content
Advertisement

Trying to add up points for correct answers in a quiz in Python

I am trying to get a program to add up points for correct answers. I am supposed to have my questions, correct answers, and candidate answers in three separate lists. The questions are to be asked one at a time and I have to return whether or not the answers are correct. I am then supposed to add up the points for each correct answer. When I run my code, it is only displaying 1 after a correct answer. I have tried putting the points variable in different places to see if that will work I have also put the “points +=” variable in different places thinking that it might be a logic problem but it still won’t do what I need it to do.

My function is below.

JavaScript

Advertisement

Answer

The main problem is that you’re resetting points to 0 inside the loop, which means that can only ever be either 0 or 1. The business with index is confusing and might be making it difficult to debug the points stuff; I suggest just using zip instead to make the whole thing easier:

JavaScript
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement