Lesson 13 of 30
Lesson 13 ? Build a guessing game
Title: Make a tiny number game
Description: Combine input, int, if, and random to build a friendly guessing game.
Why it matters for kids: Small games help you practice many skills together.
1. Pick the secret number
import random
secret_number = random.randint(1, 5)
print("I picked a number from 1 to 5.")2. Ask for a guess
guess_text = input("Your guess: ")
guess = int(guess_text)
print("You guessed:", guess)3. Check the answer
import random
secret_number = random.randint(1, 5)
guess = int(input("Guess 1 to 5: "))
if guess == secret_number:
print("You win!")
else:
print(f"Good try. The number was {secret_number}.")4. Give a hint
secret_number = 4
guess = int(input("Guess: "))
if guess == secret_number:
print("Correct!")
elif guess < secret_number:
print("Too small.")
else:
print("Too big.")5. Easy examples
favorite_number = 7
guess = 3
print(guess == favorite_number)secret_word = "dragon"
answer = input("Secret word: ")
if answer == secret_word:
print("The dragon smiles.")player_name = input("Name: ")
print(f"Good luck, {player_name}!")6. Mini challenge
Click each example to open it.
Example 1
Set secret_number = 3.
Example 2
Ask the user for one guess.
Example 3
Convert the guess with int.
Example 4
Check if the guess is correct.
Example 5
Print too small for a small guess.
Example 6
Print too big for a big guess.
Example 7
Use random.randint for the secret.
Example 8
Make the range 1 to 5.
Example 9
Make the range 1 to 10.
Example 10
Add a friendly good-bye message.