Skip to content

Week 8 of 8

Final Game Builder

The final project. Students plan and build their own small Python game, combining everything: variables to track the score, input for the player's moves, conditionals to decide what happens, a loop to keep playing, functions to stay organized, and a list with random to keep it fresh. They start from a working skeleton and make it their own.

Estimated time
60 minutes (or two sessions)
Project
Build Your Own Python Mini Game

The 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.

What you will learn

  • Plan a small game on paper before writing code.
  • Combine variables, input, conditionals, loops, functions, and randomness in one program.
  • Test the game, find bugs, and fix them as they go.
  • Change the skeleton into a game that is their own.

New words

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.

Project: Build Your Own Python Mini Game

Edit the starter code below and press Run to see it work. Use Reset starter code to go back to the original at any time.

main.py
Terminal

Run your program to see the output.

Expected output

What's your name? Alex
Welcome, Alex! Guess my secret number to win.
Pick a number from 1 to 5: 2
Nope, try again.
Pick a number from 1 to 5: 4
Nope, try again.
Pick a number from 1 to 5: 5
You got it in 3 tries, Alex!

Mini challenge

Give the player a hint: inside the loop, print Too low or Too high after each wrong guess, the way you did in Week 5.

Debugging challenge

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.

Broken code

secret = random.choice([1, 2, 3])
guess = 0
while guess != secret
    guess = int(input("Pick a number: "))
Show solution
Lines that start a block end with a colon:
while guess != secret:

Extension challenge

Redesign the skeleton into your own game: a trivia round, a story with choices, or a high-score chaser. Use at least one list, one function, and one loop.

Reflect

You built a game out of the eight ideas from this program. Which week's idea did you lean on the most, and why?

Teacher notes

Encourage a paper plan first: the goal, what the player types, and what the program says back. Because the game uses randomness, treat the expected output as one example. Celebrate small games that run over ambitious ones that do not. A short session where students play each other's games is a strong finish.

Facilitating this lesson? See the teacher & librarian guide for how to run it, common mistakes, and an offline backup activity.

Finished this lesson? Mark it complete to unlock the next week.