Step 1 – the top blocks
Here's the first section of the Scratch program.
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.
- Start with a line that says import random This line just has to be there to allow the program to generate a random number
- Then add the line to actually generate the number. The (1, 20) bit says that the number will be between 1 and 20
- Now use a print statement to add the introduction – use the Scratch algorithm to show you what to say here
- 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
- Save your program in your OneDrive (File > Save As)
Check where you're saving the program. Give it a sensible name
- Run your program (Run > Run module)
That should all work.