Ask coding questions

← Back to all posts
Randomly Printing "True" Instead of Question
eighty (1)

For reasons I can't quite work out, after answering a few questions, it'll print the text "True" instead of a question. However, it's still possible to answer the question correctly, since there's still a valid answer.

I believe this is tied to the fact that I'm checking for repeat random numbers, and something is going wrong there. I'm not sure though, and even if I was, I have no idea how to solve the problem.

Help is appreciated.

Answered by ArchieMaclean (596) [earned 5 cycles]
View Answer
Commentshotnewtop
ArchieMaclean (596)

On line 33, you set one of the questions to equal True:

questions[question_num] = True

This means that as the quiz continues, each question is set to True after it is answered.

Did you mean to do?

repeat_check[question_num] = True

Please mark as the answer if this solved your problem :)

eighty (1)

@ArchieMaclean Thanks for pointing that out! I missed that little typo.

eankeen (614)

hey!

one point of error could be that you are not checking to see if a particular element in the questions array is equal to True before printing it. On line 33, you set a particular element in the array to True. You may want to use a different array to track completed questions, or, like I said you can test if the element value is True before printing it out to the user. :)

If that is not the error, it may be that the bug is difficult to find because of the many global variables. You could refactor your code to eliminate many of the harmful global variables so you can keep track of the values easier.

hope i could help :)