From blocks to Python
You have built programs with blocks and typed some Python. The good news: the ideas are the same. Here is how each block becomes a line of text.
Matching blocks to Python
| Scratch block | Python |
|---|---|
| say [Hello] | print("Hello") |
| set [score] to (0) | score = 0 |
| change [score] by (1) | score = score + 1 |
| ask [Name?] and wait, then use answer | answer = input("Name? ") |
| repeat (10) | for i in range(10): |
| forever | while True: |
| repeat until <done> | while not done: |
| if < > then ... else | if condition: ... else: ... |
An example
Python:
score = 0
for i in range(5):
score = score + 2
print(score)
Output: 10
What changes in a text language
In exchange, text languages are faster to write for big programs, easier to share and search, and used by professional programmers.
Note that Python's range(10) counts 0 to 9, but it still repeats 10 times, just like repeat (10).
A Scratch script says: set [lives] to (3), repeat until <lives = 0> { change [lives] by (-1) }, say [Game over]. Write the Python and say what it prints.
- set [lives] to (3) becomes lives = 3.
- repeat until <lives = 0> keeps going while lives is NOT 0; here we write while lives > 0:
- change [lives] by (-1) becomes lives = lives - 1, indented.
- say [Game over] becomes print("Game over"), not indented, so it runs after the loop.
Answer: lives = 3
while lives > 0:
lives = lives - 1
print("Game over")
It prints: Game over
Every block has a Python match: say is print, set and change use =, ask is input, repeat (n) is a for loop, forever and repeat until are while loops. In Python, indentation does the job of the block's C shape.
- AND
- A Boolean operator that gives True (1) only when both inputs are True.
- Input
- Data put into a computer, for example from a keyboard, mouse, microphone or sensor.
- For loop
- A count-controlled loop that repeats a set number of times.
- Output
- Information sent out from a computer, for example to a screen, speaker or printer.
- Syntax error
- A mistake in the rules of the language, such as a missing colon or bracket, so the program cannot run.
- Not “score = 1”. score = 1 is like set [score] to (1), not change.
Try two quick questions
See if it has sunk in. Answers are marked straight away.
2 more questions
Try each one, then tap to check.
Which Python line matches the Scratch block set [score] to (0)?
- score = score + 0
- score == 0
- score = 0
- print(score)
Show the answer
Answer: score = 0
set stores a value.
Which Python loop matches the Scratch block repeat (5)?
- while True:
- if i < 5:
- repeat 5:
- for i in range(5):
Show the answer
Answer: for i in range(5):
range(5) runs 5 times.
Check you have got it
Answer 6 quick questions with instant marking. If you get one wrong, GCSE-ready shows you why and gives you another go. It is free, and you do not need an account.
Last updated 2 October 2026. Spotted a mistake? Tell us and we will fix it.