Matthew Hill7,799 Points
What is the purpose of the index in - if answer == True: ?
I wrote my program before watching the video and used this code instead:
<p> right = 0 for answer in self.answers: if answer: right += 1 </p>
It provides me with an accurate count so I'm wondering why Kenneth added an index in his code? Thanks, Matt
Steven Parker206,352 Points
If you just test answer, you're really just checking to see if the list is empty (which it is not, or you would not be inside the loop at all). You would not need a loop for that, you could just use:
So you might get the same result as using the index, but only when every answer is correct. But if any answer is wrong, the result will be different.
by testing answer, you accumulate a total of only the correct answers.