Puzzle 1 – guessing a number

Step 5 – add the guesses in

Here's an improved version of the Scratch program which counts the number of guesses the player takes.

Scratch code image

It has three things to add in.

We can do this in Python as well, using pretty much the same code.

  1. The first line to add needs to set guesses to 0
  2. Then straight after a guess use a line that goes  guesses = guesses + 1  to add a guess
  3. The last line to add is a little more complex. Use the screenshot below to add that.

Code helper image

That's this puzzle done. Can you code a linear search as well?