Day 32: Number Guessing Game
Tuesday, May 5th, 2026
Warmup
Watch the Edpuzzle video that reviews how to setup a project in Visual Studio Code. Login to Clever to find Edpuzzle.
After the Video
Start a new project in Visual Studio Code and copy the code below. This code will allow you to control a turtle using the arrow keys on your keyboard.
import turtle
# Setup
screen = turtle.Screen()
screen.title("Turtle Keyboard Control")
t = turtle.Turtle()
# Movement functions
def move_up():
t.setheading(90)
t.forward(20)
def move_down():
t.setheading(270)
t.forward(20)
def move_left():
t.setheading(180)
t.forward(20)
def move_right():
t.setheading(0)
t.forward(20)
# Bind keys
screen.listen() # Required — tells the screen to accept keyboard input
screen.onkey(move_up, "Up")
screen.onkey(move_down, "Down")
screen.onkey(move_left, "Left")
screen.onkey(move_right, "Right")
turtle.mainloop()Work Session
Follow along with Mr. Willingham. We’ll work on a number guessing game together. We’ll add features gradually and focus on the following skills.
- Variables
- Random numbers
- User input
- Conditional statements
- Loops
Cheat Codes
If things go well, we’ll have time to add some cheat codes to our game. These will allow the player to gain an advantage. What ideas can you come up with for cheat codes?
Checkpoint: Work Session
- My number guessing game generates a random number and accepts a guess from the player using
input(). - My game tells the player whether their guess is too high, too low, or correct using
if/elif/else. - My game uses a loop so the player can keep guessing until they get it right.
Closing
Today you built a complete, playable game from scratch using five core programming concepts: variables, random numbers, user input, conditionals, and loops. These are the same building blocks used in almost every real program ever written. Tomorrow we’ll use loops again to create beautiful patterns with the turtle module — and you’ll see how a few lines of code can produce surprisingly complex results.
Standards
- MS-CS-FCP.3.2 — Develop a working vocabulary of computational thinking including variables, branches, and iteration — students apply all three concepts directly while building the guessing game’s core logic.
- MS-CS-FCP.4.7 — Create a program that accepts user input and stores the result in a variable — students use
input()to collect a guess and store it in a variable on every turn. - MS-CS-FCP.4.8 — Create a computer program that implements a loop — students write a
whileloop that keeps the game running until the player guesses correctly. - MS-CS-FCP.4.9 — Develop a program that makes a decision based on data or user input — students use
if/elif/elseto compare the player’s guess to the secret number and respond with a hint.