Book a free demo

๐Ÿ•น๏ธ Interactive lesson ยท Grade 10 ยท about 90 minutes

Build two Python games: Tic-Tac-Toe and Guess the Number.

Play with the boards, dictionaries and number lines first, so the ideas make sense. Then follow guided step cards to write each program yourself and run it in a real Python console in your browser.

  • Grade 10 (ages 14-16)
  • 2 game tracks
  • Real Python console
  • Free jump for teachers
  • Free ยท no sign-up
ShareWhatsApp

Loading the lessonโ€ฆ

What students learn

  • How a game's rules become Python data (a dictionary of squares) and control flow (loops and if statements)
  • Storing a board in a dictionary keyed like a numpad, and resetting it with a list of keys
  • Writing a function that prints the board with print() and string joining
  • Validating moves, counting turns, switching players, and why we only check for a win once count >= 5
  • All 8 winning lines with chained comparisons, and why each ends with != ' '
  • random.randint, time.sleep, global, and the remainder operator (% 2 == 0) for an even/odd clue
  • Using while with a guess counter, break, range checks, and a try / except shield that stops crashes on bad input

The seven modules

  1. Warm-up: how computers think in games. Click a numpad Tic-Tac-Toe board and a secret-number radar while the real Python variables update underneath.
  2. Tic-Tac-Toe part 1: the numpad dictionary and board printer. Toggle squares and watch the matching dictionary key light up, run printBoard() line by line, and reset with a board_keys loop.
  3. Tic-Tac-Toe part 2: turns, validation and the 8 win lines. Slide count from 1 to 9 to see why a win needs 5 moves, scan all 8 lines, and catch the bug that appears if you forget != ' '.
  4. Guided activity 1: code Tic-Tac-Toe in 13 steps. Step cards, auto-fill, an Explain Line button and a Run Python Code console where you actually play your game.
  5. Guess the Number: random, hints and try/except. A number line that slices as you guess, an even/odd badge, and a crash-shield simulator that tests 50, 150 and banana.
  6. Guided activity 2: code Guess the Number in 12 steps. Build the intro, guess loop, hints, range checks, the try/except shield and a play-again loop, then play it.
  7. Eye break, recap and certificate. A calming eye exercise, rapid-fire revision cards and a certificate, plus both finished .py files to keep.

FAQ

Python game lab: common questions

How do you make Tic-Tac-Toe in Python?

Store the board in a dictionary whose keys are the squares ('7' to '1' like a numpad) and whose values are ' ', 'X' or 'O'. Use a loop that prints the board, reads a move with input(), checks the square is empty, places the mark, counts moves, checks the 8 winning lines once count is 5 or more, and then switches the player.

How do you check for a winner in Python Tic-Tac-Toe?

Compare three squares in a chain, for example theBoard['7'] == theBoard['8'] == theBoard['9'] != ' '. There are 8 winning lines: 3 rows, 3 columns and 2 diagonals. The != ' ' at the end stops three empty squares from counting as a win.

Why check for a win only when count is 5 or more?

X plays moves 1, 3 and 5, so the earliest anyone can have three marks (and a line) is move 5. Checking earlier cannot find a winner.

How do you write a Guess the Number game in Python?

Pick a secret with random.randint(1, 100), loop while the guess count is below the limit, read each guess with input(), convert it with int(), compare it to the secret to print too low or too high, and break when it matches. Wrap int() in try / except so typing letters doesn't crash the program.

What does try / except do?

Python tries the code in the try block. If it raises an error (like int('banana') raising a ValueError), the except block runs instead and the program carries on, so you can print a friendly message.

Do I need to install Python for this lesson?

No. The lesson includes a Python console that runs in your browser, so you can write and play both games without installing anything.

Start a conversation

Questions about coding classes?

Tell us the learner's age and level and we'll suggest a starting point and confirm the format before anything is booked.

  • Tell us the learnerโ€™s age or grade and goals
  • Weโ€™ll suggest a suitable class or learning path
  • Weโ€™ll confirm format, timing and fees with a parent or guardian

For a childโ€™s class, please have a parent or guardian send the enquiry. Avoid sharing passwords or sensitive personal details.

Weโ€™ll use your details only to respond to this request.

Play it, don't just read it

Take a break and play

Free games that need no sign-up. Pick one and play for five minutes.

All free games โ†’
Chat on WhatsApp
Esc

Try