Free Python worksheets for beginners
Seven printable worksheets that take beginners from print() to lists. Each one has three parts: predict the output, fix the bug, and write your own code, with a full answer key. Print one, print them all, or use them on screen.
How to use these worksheets
- Part A, predict: learners write down what the code will print, without running it. This is the best test of whether an idea has really sunk in.
- Part B, fix the bug: each program has one mistake. Learners find it and write the corrected line.
- Part C, write it: short tasks to write from scratch, on paper or on a computer.
Every answer in the key was produced by running the code with real Python, so you can trust it. Learners can check their own predictions by typing the code into the practice pages or any Python.
Python worksheet 1 of 7
print() and text
A. What will this print?
print("Hello") print("World")print("Ha" * 3)print("Cat", "Dog", 7)print("Line one\nLine two")
B. Find and fix the bug
print("Hello world)Print("Hi")
C. Write it
Print your name and your favourite food on two separate lines.
Use * to print a row of 20 dashes.
Practise this on screen: Game 4, Sky Writer · www.pythoncodinggames.com
Show the answers
Answers: worksheet 1, print() and text
A. What will this print?
Hello World
HaHaHa
Cat Dog 7
Line one Line two
B. Find and fix the bug
print("Hello world")The text needs a closing quote mark.
print("Hi")print is all lower case. Python sees Print as a different name.
C. Write it (one possible answer)
print("My name is Sam") print("I like pizza")Output:
My name is Sam I like pizza
print("-" * 20)Output:
--------------------
Python worksheet 2 of 7
Variables and maths
A. What will this print?
a = 5 b = 3 print(a + b)score = 10 score = score + 5 print(score)print(7 // 2) print(7 % 2)x = 2 y = x x = 9 print(x, y)
B. Find and fix the bug
total = 10 print(Total)apples = 4 print("I have " + apples + " apples")
C. Write it
A room is 5 metres long and 4 metres wide. Store both in variables, then print the area.
Start a variable coins at 0. Add 3, then add 7, then print it.
Practise this on screen: Game 9, Box Depot · www.pythoncodinggames.com
Show the answers
Answers: worksheet 2, Variables and maths
A. What will this print?
8
15
3 1
9 2
B. Find and fix the bug
total = 10 print(total)Names must match exactly, capitals too: total, not Total.
apples = 4 print(f"I have {apples} apples")You can't join text and a number with +. Use an f-string, or str(apples).
C. Write it (one possible answer)
length = 5 width = 4 print(length * width)Output:
20
coins = 0 coins = coins + 3 coins = coins + 7 print(coins)Output:
10
Python worksheet 3 of 7
input() and types
A. What will this print?
age = input("Age? ") print(age + "1")The user types 9.
age = int(input("Age? ")) print(age + 1)The user types 9.
print(type(3.5)) print(type("3.5"))name = "Ada" print(f"Hi {name}, you have {2 + 3} messages")
B. Find and fix the bug
number = input("Number? ") print(number * 2)The user types 4. It should print 8.
print("You are " + 12 + " years old")
C. Write it
Ask for the user's name, then print Hello, followed by their name.
Ask for two numbers and print their total.
Practise this on screen: Game 18, Ticket Booth · www.pythoncodinggames.com
Show the answers
Answers: worksheet 3, input() and types
A. What will this print?
91
10
<class 'float'> <class 'str'>
Hi Ada, you have 5 messages
B. Find and fix the bug
number = int(input("Number? ")) print(number * 2)It prints 44, because input() gives text and text * 2 repeats it. int() makes it a number, so it prints 8.
print("You are " + str(12) + " years old")Text and a number can't be joined with +. str() turns the number into text.
C. Write it (one possible answer)
name = input("What is your name? ") print(f"Hello, {name}!")Output (with the answers Ada):
What is your name? Ada Hello, Ada!
a = int(input("First number: ")) b = int(input("Second number: ")) print(a + b)Output (with the answers 3, 4):
First number: 3 Second number: 4 7
Python worksheet 4 of 7
if, elif and else
A. What will this print?
x = 7 if x > 5: print("big") print("done")temp = 12 if temp > 25: print("hot") elif temp > 10: print("mild") else: print("cold")n = 4 if n % 2 == 0: print("even") else: print("odd")age = 15 if age >= 13 and age <= 19: print("teen") print("bye")
B. Find and fix the bug
if 5 > 3 print("yes")score = 50 if score = 50: print("half")
C. Write it
Ask for a number. Print positive, negative or zero.
Ask for a test score out of 100. Print Pass if it's 50 or more, and Try again if not.
Practise this on screen: Game 22, Rain or Shine · www.pythoncodinggames.com
Show the answers
Answers: worksheet 4, if, elif and else
A. What will this print?
big done
mild
even
teen bye
B. Find and fix the bug
if 5 > 3: print("yes")An if line must end with a colon.
score = 50 if score == 50: print("half")To compare, use two equals signs: ==. One = stores a value.
C. Write it (one possible answer)
n = int(input("Number: ")) if n > 0: print("positive") elif n < 0: print("negative") else: print("zero")Output (with the answers -4):
Number: -4 negative
score = int(input("Score: ")) if score >= 50: print("Pass") else: print("Try again")Output (with the answers 72):
Score: 72 Pass
Python worksheet 5 of 7
Loops
A. What will this print?
for i in range(3): print(i)for i in range(1, 10, 3): print(i)total = 0 for n in range(1, 5): total = total + n print(total)count = 3 while count > 0: print(count) count = count - 1 print("Go!")
B. Find and fix the bug
for i in range(5) print(i)count = 1 while count <= 3: print(count) count = count + 1
C. Write it
Print the numbers 1 to 10 using a for loop.
Print a triangle of stars: 1 star on the first line, 2 on the next, up to 5.
Practise this on screen: Game 31, Fence Builder · www.pythoncodinggames.com
Show the answers
Answers: worksheet 5, Loops
A. What will this print?
0 1 2
1 4 7
10
3 2 1 Go!
B. Find and fix the bug
for i in range(5): print(i)A for line must end with a colon.
count = 1 while count <= 3: print(count) count = count + 1The lines inside the loop must be indented by 4 spaces.
C. Write it (one possible answer)
for n in range(1, 11): print(n)Output:
1 2 3 4 5 6 7 8 9 10
for n in range(1, 6): print("*" * n)Output:
* ** *** **** *****
Python worksheet 6 of 7
Functions
A. What will this print?
def greet(name): print("Hi", name) greet("Ada") greet("Sam")def double(n): return n * 2 print(double(4) + 1)def area(w, h=2): return w * h print(area(5)) print(area(5, 3))def shout(word): print(word.upper()) result = shout("hi") print(result)
B. Find and fix the bug
def add(a, b): a + b print(add(2, 3))It should print 5.
greet("Ada") def greet(name): print("Hi", name)
C. Write it
Write a function square(n) that returns n times n. Print square(6).
Write a function is_even(n) that returns True or False. Print is_even(10) and is_even(7).
Practise this on screen: Game 38, Dance Floor · www.pythoncodinggames.com
Show the answers
Answers: worksheet 6, Functions
A. What will this print?
Hi Ada Hi Sam
9
10 15
HI None
B. Find and fix the bug
def add(a, b): return a + b print(add(2, 3))It prints None. The function works out a + b but never gives it back. Add return.
def greet(name): print("Hi", name) greet("Ada")Python reads from the top, so the def must come before the line that calls it.
C. Write it (one possible answer)
def square(n): return n * n print(square(6))Output:
36
def is_even(n): return n % 2 == 0 print(is_even(10)) print(is_even(7))Output:
True False
Python worksheet 7 of 7
Lists
A. What will this print?
pets = ["cat", "dog", "fish"] print(pets[0]) print(pets[-1])pets = ["cat", "dog"] pets.append("owl") print(len(pets))nums = [4, 8, 15] print(nums[1] + nums[2])for colour in ["red", "blue"]: print(colour.upper())
B. Find and fix the bug
pets = ["cat", "dog", "fish"] print(pets[3])scores = [3, 9, 4] scores.add(7) print(scores)
C. Write it
Make a list of 3 favourite foods, and print each one using a for loop.
Given nums = [3, 9, 4, 12], print the biggest number without using max().
Practise this on screen: Game 47, Train Yard · www.pythoncodinggames.com
Show the answers
Answers: worksheet 7, Lists
A. What will this print?
cat fish
3
23
RED BLUE
B. Find and fix the bug
pets = ["cat", "dog", "fish"] print(pets[2])Positions start at 0, so the third item is pets[2]. There's no pets[3].
scores = [3, 9, 4] scores.append(7) print(scores)Lists use append() to add an item to the end.
C. Write it (one possible answer)
foods = ["pizza", "noodles", "mango"] for food in foods: print(food)Output:
pizza noodles mango
nums = [3, 9, 4, 12] biggest = nums[0] for n in nums: if n > biggest: biggest = n print(biggest)Output:
12
Make the most of them
- Use one worksheet a week, alongside the 6-week Scratch to Python plan.
- Let learners check Part A by running the code afterwards. Wrong predictions are where the learning happens.
- Each worksheet matches a game in the course, named at the top, if you'd like learners to practise the same idea on screen.
Play the game version
Each of these games teaches one idea from this page, with a short narrated video and six levels to clear.
Questions people ask
Are these Python worksheets free?
Yes. They're free to print and use with your own class, club or family. Please link to this page rather than re-uploading them.
Do the worksheets come with answers?
Yes. Each worksheet has a full answer key, worked out by running the code with real Python. Print with or without it.
What age are these worksheets for?
They suit beginners from about 10 years old to adults. No Python knowledge is needed for worksheet 1, and each one builds on the one before.
Do students need a computer?
Parts A and B are designed for paper. Part C can be done on paper too, but it's more fun to type it in and run it.
Learn Python with games
Every idea on this page has its own game in the course, with a short video and six levels. The three games in Module 1 are free: no account, nothing to install.
Every idea on this page has its own game in the course. Pick up where you left off.
Play the first game freeContinue the courseMore teach
More free ways to learn
Fun Python code
Fun, cool Python code for beginners: I love you in Python, heart code, happy birthday programs, a rocket countdown and more. Run each one in your browser.
Practice
Free Python practice online: exercises with answers you check in your browser, plus 79 coding games, one for every beginner topic.
Guides
Short guides on learning Python with games, how long it takes, and where to start.