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.

Practise this lesson free (6 questions)

Matching blocks to Python

In Scratch the blocks inside a loop are wrapped in its C shape. In Python they are indented.
Scratch blockPython
say [Hello]print("Hello")
set [score] to (0)score = 0
change [score] by (1)score = score + 1
ask [Name?] and wait, then use answeranswer = input("Name? ")
repeat (10)for i in range(10):
foreverwhile True:
repeat until <done>while not done:
if < > then ... elseif condition: ... else: ...

An example

Scratch: set [score] to (0), then repeat (5) { change [score] by (2) }, then say (score).
Python:
score = 0
for i in range(5):
    score = score + 2
print(score)
Output: 10

What changes in a text language

In a text language you must get the spelling, punctuation and indentation exactly right, or you get a syntax error.
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).
Worked example

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.

  1. set [lives] to (3) becomes lives = 3.
  2. repeat until <lives = 0> keeps going while lives is NOT 0; here we write while lives > 0:
  3. change [lives] by (-1) becomes lives = lives - 1, indented.
  4. 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

Key idea

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.

Key words
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.

All KS3 Computing key terms and definitions →

Common mistakes
Quick check

Try two quick questions

See if it has sunk in. Answers are marked straight away.

Extra practice

2 more questions

Try each one, then tap to check.

  1. Which Python line matches the Scratch block set [score] to (0)?

    1. score = score + 0
    2. score == 0
    3. score = 0
    4. print(score)
    Show the answer

    Answer: score = 0

    set stores a value.

  2. Which Python loop matches the Scratch block repeat (5)?

    1. while True:
    2. if i < 5:
    3. repeat 5:
    4. 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.

Video for this lesson coming soon. Subscribe on YouTube

Sources and references

Last updated 2 October 2026. Spotted a mistake? Tell us and we will fix it.