Puzzle 2 – create an AI bot to guess a number

Step 1 – the top blocks

Here's the first section of the Scratch program.

Scratch code image

This starts the program (the Green Flag block), sets up two variables (guesses and number), and then introduces the program using the purple Say blocks.

This is all pretty much the same in Scratch, although we don't need the Green Flag block. And there's just one thing we need to add to this.

  1. Start by setting the variable guesses to 0. This is going to keep a count on the number of guesses the computer has made.
  2. Then set the variable number to 1 – the computer will start guessing from 1
  3. Now use two  print statements to add the introductions – use the Scratch algorithm to show you what to say here
  4. Then we need to set  answer = "N"  Python has to know what the answer (the player's response) might be before it can get on with the main bit of the question. "N" means the guess was wrong, so it makes sense to set it to that first
  5. Save your program in your OneDrive (File > Save As)

    Check where you're saving the program. Give it a sensible name

  6. Run your program (Run > Run module)

Code helper image

That should all work.