Ask coding questions

← Back to all posts
Multiple-Choice Quiz
YYChen3 (1)

I've got two levels, once you choose one and complete it, you will get a question 'Choose another level', but after I press the second level, it stops. I need some advice on how to keep it running. Please help! Thank you!

Answered by SixBeeps (5353) [earned 5 cycles]
View Answer
SixBeeps (5353)

You don't have code to go back to the beginning, so that second choice gets interpreted as Python. Neither a nor b are valid Python code, so that's why you're getting an error.
To make your code go back to the beginning, put your whole program in a while loop:

while True:
  score = 0
  print ("Welcome to THE quiz!")
  # ...
YYChen3 (1)

I've tried it, it still doesn't work. @SixBeeps

SixBeeps (5353)

@YYChen3 Looks like you got rid of it while I was away. Did you put everything under the while? (As in, did you indent everything as well?)

YYChen3 (1)

Yes, I did. But it still didn't work. @SixBeeps

SixBeeps (5353)

@YYChen3 You didn't indent everything

SixBeeps (5353)

@YYChen3 Everything needs to be included

SixBeeps (5353)

@YYChen3 Honestly it's better to just select everything under the while and hit tab

ch1ck3n (2388)

I don't get any error. the program just stops.

YYChen3 (1)

Sorry, that's what I meant. @ch1cken