Lesson 16: Mini-Project: The Number-Guessing Game

The lesson’s game, with one demo change: the secret number is fixed at 7 for demo purposes, so you can test the logic. In the real game you write in IDLE, the secret is random every time (random.randint(1, 10)). Guess a number from 1 to 10, press Run, and real Python tells you too low, too high, or you got it.

Loading Python… this can take a few seconds the first time. Please wait — the Run button will become available when Python is ready.

Try this: Guess 5 first (too low), then 9 (too high), then 7 — and watch Python’s message change each time.

The code that checks each guess (real Python)



Output

Press Run to make your first guess.
Demo secret = 7 (fixed, so you can learn the logic). The full game in Lesson 16 picks a fresh random secret every run — run it in IDLE to play for real.