This was one of the first programs I wrote while learning Python. The computer picks a number from 1 to 100, you guess it, and it tells you whether you're too high or too low. It's small, but it covers the basics: loops, input validation, and keeping the logic separate so it can be tested.
I've since added a browser version called Hot or Cold, so you can play without installing anything. It has a heat meter and a number line that shrinks as you close in.
Play in your browser: https://dave-4u.github.io/python-number-guessing/
./run.sh # play in the terminal (Python 3.8+)
./run.sh test # run the unit testsOn Windows: python guess.py and python -m unittest discover -s tests -t .
Number Guessing Game
I picked a number from 1 to 100. Try to guess it. (type q to quit)
Your guess: 50
Too high.
Your guess: 25
Too low.
- Terminal: friendly input validation,
qto quit, play-again prompt, and your best score for the session - Browser (
docs/index.html):- heat meter (freezing → on fire)
- a 1–100 number line that greys out the numbers it can't be
- guess history chips, a gentle shake for invalid or repeated guesses, and confetti when you win
- best score saved in your browser, and keyboard play (
Enter,Nfor a new number)
- Logic is split into
check_guess()andparse_guess(), with tests intests/
Python 3 (standard library only) and unittest. The web version is a single HTML file with vanilla JS.
- Difficulty levels (1–50, 1–1000)
- A "you play the computer" mode where it guesses your number with binary search
MIT © Adegboro David Oluwadamilare
