Puzzle 1 – guessing 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), generates a random number, and then introduces the program using the purple Say block.

There are a couple of things that are a bit different in Python. There's no need for a Green Flag block, but we do have to do something first that we don't need to do in Scratch.

  1. Start with a line that says  import random  This line just has to be there to allow the program to generate a random number
  2. Then add the line to actually generate the number. The (1, 20) bit says that the number will be between 1 and 20
  3. Now use a  print statement to add the introduction – use the Scratch algorithm to show you what to say here
  4. Then we need to set  answer = 0  Python has to know what the answer (the player's guess) might be before it can get on with the main bit of the question. 0 can never be right so it's a good number to set it to to start with
  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.