Student worksheets
Intro to Python Programming
One printable worksheet per lesson, for students working on paper or away from a screen. Use your browser's print option to print all worksheets, or a single page.
Intro to Python · Worksheet 1 of 8
Name: _______________ Date: __________
Week 1: What is Python?
Key idea
Code is a list of instructions, and the computer follows them in order without guessing. print() is the first instruction you will learn: it shows exactly the text between the quotation marks. Change the words in the quotes and the screen changes with them.
Vocabulary
- program
- A set of exact instructions the computer follows, one line at a time.
- print()
- A Python command that shows whatever text you put in the quotes on the screen.
- string
- A piece of text inside quotation marks, like "Hello".
- output
- Whatever the program shows on the screen when it runs.
- error
- The message Python shows when a line is written in a way it cannot follow.
Plan your code
Project: Digital Introduction Card. Write, step by step, what your program should do.
Debugging question
This line should print the word Hello, but it stops the program with an error instead. Look at what is missing around the word Hello. Every piece of text in Python needs it.
print(Hello)Write the fix:
Reflection
The computer followed your lines in the exact order you wrote them. In the game you build at the end of this program, order will matter too. What would go wrong if a game printed "You win!" before the player even took a turn?
Intro to Python · Worksheet 2 of 8
Name: _______________ Date: __________
Week 2: Variables and Data Types
Key idea
A variable is a labeled box: you put a value in it once, then use its name anywhere you want that value. Text goes in quotation marks (a string); numbers do not. With an f-string you can drop a variable straight into a sentence, so a program can greet a player by name instead of saying the same thing every time.
Vocabulary
- variable
- A named box that stores a value so you can use it again later.
- assign
- To put a value into a variable using the = sign.
- integer
- A whole number with no decimal point, like 10.
- f-string
- A sentence that starts with f, where anything inside { } is filled in from a variable.
Plan your code
Project: About Me Generator. Write, step by step, what your program should do.
Debugging question
This should print My name is Alex, but it prints the word name instead. The variable's value is not getting filled in. What has to go around name inside an f-string?
name = "Alex"
print(f"My name is name.")Write the fix:
Reflection
You changed what the program says just by changing one variable. Why is that better than typing the player's name over and over in every line?
Intro to Python · Worksheet 3 of 8
Name: _______________ Date: __________
Week 3: Input and Interaction
Key idea
input() is how a program listens. It shows a prompt, then stops and waits for the player to type and press Enter. Their answer gets stored in a variable, so the program can use it - their name, their guess, their choice - in what it does next. Keep in mind: input() always gives back text.
Vocabulary
- input()
- A Python command that asks a question and waits for the user to type an answer.
- prompt
- The message input() shows to tell the user what to type.
- user
- The person using the program - in a game, the player.
Plan your code
Project: Mini Chatbot. Write, step by step, what your program should do.
Debugging question
Running this causes an error before the question even shows up. The message inside input() is text for the user to read. What does every piece of text need around it?
name = input(What should I call you? )Write the fix:
Reflection
Last week your program always said the same thing. Now it answers you. What could you ask a player at the start of a game to make it feel like it is about them?
Intro to Python · Worksheet 4 of 8
Name: _______________ Date: __________
Week 4: Conditionals
Key idea
A conditional lets the program choose. Python checks a condition - something that is either true or false - and runs the indented lines under it only if the condition is true. With if, elif, and else, a program can react one way to a right answer, another to a close answer, and another to a wrong one. That is how a game decides whether you scored, won, or lost.
Vocabulary
- condition
- A question with a true or false answer, like answer == "Earth".
- if
- Runs the indented lines below it only when its condition is true.
- elif
- Checks another condition when the ones above it were false.
- else
- Runs when none of the conditions above it were true.
- ==
- Checks whether two values are equal (different from =, which stores a value).
Plan your code
Project: Trivia or Personality Quiz. Write, step by step, what your program should do.
Debugging question
Python shows an error on the if line. One equals sign stores a value in a variable. What do you use when you want to check whether two things are the same?
answer = input("Which planet do we live on? ")
if answer = "Earth":
print("Correct!")Write the fix:
Reflection
Your program now reacts differently to different answers. In your final game, what is one decision the program will need to make, and what should happen for each choice?
Intro to Python · Worksheet 5 of 8
Name: _______________ Date: __________
Week 5: Loops
Key idea
A loop repeats code so you do not have to write it a hundred times. A while loop keeps going as long as its condition is true - perfect for a game that should keep asking until the player wins. Something inside the loop has to eventually make the condition false, or it runs forever. Since input() gives text, we use int() to turn the guess into a number we can compare.
Vocabulary
- loop
- Code that repeats instead of running once.
- while
- Repeats the lines below it as long as its condition stays true.
- int()
- Turns typed text like "7" into the number 7 so you can compare it.
- infinite loop
- A loop that never stops because its condition never becomes false.
Plan your code
Project: Guess the Number Game. Write, step by step, what your program should do.
Debugging question
This game never ends, even when the player types 7. The secret is the number 7, but input() gives back the text "7". Why are they not equal, and what turns text into a number?
secret = 7
guess = 0
while guess != secret:
guess = input("Guess a number from 1 to 10: ")Write the fix:
Reflection
A loop let you ask again and again without repeating yourself. What part of your final game might need to repeat - the turns, the questions, the rounds?
Intro to Python · Worksheet 6 of 8
Name: _______________ Date: __________
Week 6: Functions
Key idea
A function is a reusable recipe. You write the steps once after def and give it a name; after that, you run all those steps just by calling the name. A parameter lets you hand the function different information each time, so one greet function can welcome any player. Writing a function does not run it; calling it does.
Vocabulary
- function
- A named block of code you can run again and again by calling its name.
- def
- The keyword that creates a new function.
- parameter
- An input a function takes, listed inside its parentheses.
- call
- To run a function by writing its name with parentheses, like greet("Alex").
Plan your code
Project: Game Helper Functions. Write, step by step, what your program should do.
Debugging question
This stops with an error about a missing argument. The greet function asks for a player in its parentheses. Look at the last line - what did the call forget to give it?
def greet(player):
print(f"Welcome, {player}!")
greet()Write the fix:
Reflection
You wrote show_score once and used it twice. In your final game, what is something you will do more than once that could become a function?
Intro to Python · Worksheet 7 of 8
Name: _______________ Date: __________
Week 7: Lists and Randomness
Key idea
A list holds many values in one variable, written inside square brackets. random.choice() reaches into a list and pulls out one item at random, so the program can surprise the player. To use random you first bring it in with import random at the top - the first time you have needed a tool that is not built in. Lists plus randomness are what make a game feel different every time you play.
Vocabulary
- list
- An ordered collection of values inside square brackets, like ["a", "b", "c"].
- item
- One value stored in a list.
- import
- Brings in extra tools Python does not load by default, like the random module.
- random.choice()
- Picks one item from a list at random.
Plan your code
Project: Random Adventure Game. Write, step by step, what your program should do.
Debugging question
Python says random is not defined. This program uses random.choice(), but random is a tool that has to be brought in first. What single line belongs at the very top?
paths = ["a dark forest", "a quiet cave"]
path = random.choice(paths)
print(path)Write the fix:
Reflection
Two players run this and get different stories. Why does that make a game more fun to play more than once?
Intro to Python · Worksheet 8 of 8
Name: _______________ Date: __________
Week 8: Final Game Builder
Key idea
Real programs are built from small pieces you already know, added one at a time. Start with a plan and a skeleton that runs, then add one feature, test it, and only then add the next. A small game that works is a real win - more than a big one that never runs.
Vocabulary
- plan
- A short outline of what a program should do, written before you code it.
- skeleton
- A small working program you start from and build onto.
- test
- Running your program with different inputs to see whether it works.
- bug
- A mistake in code that makes the program do the wrong thing.
Plan your code
Project: Build Your Own Python Mini Game. Write, step by step, what your program should do.
Debugging question
Python points at the while line with a syntax error. Every line that starts a block - if, while, def - ends with the same small symbol. Look at the end of that line.
secret = random.choice([1, 2, 3])
guess = 0
while guess != secret
guess = int(input("Pick a number: "))Write the fix:
Reflection
You built a game out of the eight ideas from this program. Which week's idea did you lean on the most, and why?