Step 1 of 5

Step 1 · Read and run

Play it

This chapter's project is a classic: guess the number. The program knows a secret number, and after each guess it tells you whether to go higher or lower.

It's a while True: loop, because nobody knows how many guesses it will take. A counter keeps track of the guesses, and break ends the game when you get it.

The secret here is fixed in the code, so peek if you like. In Chapter 14 the computer will pick a random one.

Run the program to carry on.
guess.py

Output

Press Run to see what your program prints.