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

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

Name: ____________________Date: ____________

A. What will this print?

  1. print("Hello")
    print("World")
  2. print("Ha" * 3)
  3. print("Cat", "Dog", 7)
  4. print("Line one\nLine two")

B. Find and fix the bug

  1. print("Hello world)
  2. Print("Hi")

C. Write it

  1. Print your name and your favourite food on two separate lines.

  2. 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?
  1. Hello
    World
  2. HaHaHa
  3. Cat Dog 7
  4. Line one
    Line two
B. Find and fix the bug
  1. print("Hello world")

    The text needs a closing quote mark.

  2. print("Hi")

    print is all lower case. Python sees Print as a different name.

C. Write it (one possible answer)
  1. print("My name is Sam")
    print("I like pizza")

    Output:

    My name is Sam
    I like pizza
  2. print("-" * 20)

    Output:

    --------------------

Python worksheet 2 of 7

Variables and maths

Name: ____________________Date: ____________

A. What will this print?

  1. a = 5
    b = 3
    print(a + b)
  2. score = 10
    score = score + 5
    print(score)
  3. print(7 // 2)
    print(7 % 2)
  4. x = 2
    y = x
    x = 9
    print(x, y)

B. Find and fix the bug

  1. total = 10
    print(Total)
  2. apples = 4
    print("I have " + apples + " apples")

C. Write it

  1. A room is 5 metres long and 4 metres wide. Store both in variables, then print the area.

  2. 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?
  1. 8
  2. 15
  3. 3
    1
  4. 9 2
B. Find and fix the bug
  1. total = 10
    print(total)

    Names must match exactly, capitals too: total, not Total.

  2. 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)
  1. length = 5
    width = 4
    print(length * width)

    Output:

    20
  2. coins = 0
    coins = coins + 3
    coins = coins + 7
    print(coins)

    Output:

    10

Python worksheet 3 of 7

input() and types

Name: ____________________Date: ____________

A. What will this print?

  1. age = input("Age? ")
    print(age + "1")

    The user types 9.

  2. age = int(input("Age? "))
    print(age + 1)

    The user types 9.

  3. print(type(3.5))
    print(type("3.5"))
  4. name = "Ada"
    print(f"Hi {name}, you have {2 + 3} messages")

B. Find and fix the bug

  1. number = input("Number? ")
    print(number * 2)

    The user types 4. It should print 8.

  2. print("You are " + 12 + " years old")

C. Write it

  1. Ask for the user's name, then print Hello, followed by their name.

  2. 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?
  1. 91
  2. 10
  3. <class 'float'>
    <class 'str'>
  4. Hi Ada, you have 5 messages
B. Find and fix the bug
  1. 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.

  2. 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)
  1. name = input("What is your name? ")
    print(f"Hello, {name}!")

    Output (with the answers Ada):

    What is your name? Ada
    Hello, Ada!
  2. 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

Name: ____________________Date: ____________

A. What will this print?

  1. x = 7
    if x > 5:
        print("big")
    print("done")
  2. temp = 12
    if temp > 25:
        print("hot")
    elif temp > 10:
        print("mild")
    else:
        print("cold")
  3. n = 4
    if n % 2 == 0:
        print("even")
    else:
        print("odd")
  4. age = 15
    if age >= 13 and age <= 19:
        print("teen")
    print("bye")

B. Find and fix the bug

  1. if 5 > 3
        print("yes")
  2. score = 50
    if score = 50:
        print("half")

C. Write it

  1. Ask for a number. Print positive, negative or zero.

  2. 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?
  1. big
    done
  2. mild
  3. even
  4. teen
    bye
B. Find and fix the bug
  1. if 5 > 3:
        print("yes")

    An if line must end with a colon.

  2. score = 50
    if score == 50:
        print("half")

    To compare, use two equals signs: ==. One = stores a value.

C. Write it (one possible answer)
  1. 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
  2. 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

Name: ____________________Date: ____________

A. What will this print?

  1. for i in range(3):
        print(i)
  2. for i in range(1, 10, 3):
        print(i)
  3. total = 0
    for n in range(1, 5):
        total = total + n
    print(total)
  4. count = 3
    while count > 0:
        print(count)
        count = count - 1
    print("Go!")

B. Find and fix the bug

  1. for i in range(5)
        print(i)
  2. count = 1
    while count <= 3:
    print(count)
    count = count + 1

C. Write it

  1. Print the numbers 1 to 10 using a for loop.

  2. 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?
  1. 0
    1
    2
  2. 1
    4
    7
  3. 10
  4. 3
    2
    1
    Go!
B. Find and fix the bug
  1. for i in range(5):
        print(i)

    A for line must end with a colon.

  2. count = 1
    while count <= 3:
        print(count)
        count = count + 1

    The lines inside the loop must be indented by 4 spaces.

C. Write it (one possible answer)
  1. for n in range(1, 11):
        print(n)

    Output:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
  2. for n in range(1, 6):
        print("*" * n)

    Output:

    *
    **
    ***
    ****
    *****

Python worksheet 6 of 7

Functions

Name: ____________________Date: ____________

A. What will this print?

  1. def greet(name):
        print("Hi", name)
    
    greet("Ada")
    greet("Sam")
  2. def double(n):
        return n * 2
    
    print(double(4) + 1)
  3. def area(w, h=2):
        return w * h
    
    print(area(5))
    print(area(5, 3))
  4. def shout(word):
        print(word.upper())
    
    result = shout("hi")
    print(result)

B. Find and fix the bug

  1. def add(a, b):
        a + b
    
    print(add(2, 3))

    It should print 5.

  2. greet("Ada")
    
    def greet(name):
        print("Hi", name)

C. Write it

  1. Write a function square(n) that returns n times n. Print square(6).

  2. 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?
  1. Hi Ada
    Hi Sam
  2. 9
  3. 10
    15
  4. HI
    None
B. Find and fix the bug
  1. 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.

  2. 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)
  1. def square(n):
        return n * n
    
    print(square(6))

    Output:

    36
  2. 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

Name: ____________________Date: ____________

A. What will this print?

  1. pets = ["cat", "dog", "fish"]
    print(pets[0])
    print(pets[-1])
  2. pets = ["cat", "dog"]
    pets.append("owl")
    print(len(pets))
  3. nums = [4, 8, 15]
    print(nums[1] + nums[2])
  4. for colour in ["red", "blue"]:
        print(colour.upper())

B. Find and fix the bug

  1. pets = ["cat", "dog", "fish"]
    print(pets[3])
  2. scores = [3, 9, 4]
    scores.add(7)
    print(scores)

C. Write it

  1. Make a list of 3 favourite foods, and print each one using a for loop.

  2. 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?
  1. cat
    fish
  2. 3
  3. 23
  4. RED
    BLUE
B. Find and fix the bug
  1. pets = ["cat", "dog", "fish"]
    print(pets[2])

    Positions start at 0, so the third item is pets[2]. There's no pets[3].

  2. 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)
  1. foods = ["pizza", "noodles", "mango"]
    for food in foods:
        print(food)

    Output:

    pizza
    noodles
    mango
  2. 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

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 course

More teach