Riddle me this – it's all Greek to me

Step 6 – Repeating until it's right

The problem with our program so far is that it only asks the riddle once.

I guess the Sphinx might just eat you if you get it wrong first time, but maybe we should play fair and give the guesser three guesses.

To do this we're going to have to use a loop to repeat the code.

THEORY: a loop is where we use repetition.
Repetition repeats a section of code, either a set number of times or until something is "correct".
The while loop we'll use here repeats the code until the answer is right. It uses a variable called correct to check if the answer given is correct or not – can you see where it changes correct to True?

Code helper image
  1. You're going to need to CHANGE YOUR CODE to how it looks in the screenshot

    This only adds 3 lines of code BUT you need to change a lot of indents

    IMPORTANT: make sure that you indent the code as shown. The indents need to be the same each time. You can use the Tab key on the keyboard to indent four spaces in one go.

    This uses a while loop to keep asking until the answer is right

    Can you see that I've used a new variable called correct to use to tell the program is the answer is correct?

  2. Run your code to check that it works

    Don't forget the quotes (") and brackets. And the idents are really important

    If your loop gets stuck and you can't stop the progam, just close the window down that the program is running in. Python will ask you if you want to "kill" the program (dramatic!). Say yes.

Loops let you keep going until something happens. Of course, if you don't get the right answer the loop will never stop. You'll be stuck here forever.

THEORY: this program uses a while loop to do repetition. Another type of loop that can be used is a for loop.