5 Simple Python Games in Under 20 Lines

Short programs are the best way to see how a game works without getting lost. Each one below is under 20 lines and runs right on this page: press Run, play, then change something and run it again.

1. Odd or Even

The computer picks a number from 1 to 10. You call odd or even. Teaches % (remainder).

example 1 · press Run, then edit and run again

2. Countdown launcher

A countdown with time.sleep() and a for loop that counts backwards.

example 2 · press Run, then edit and run again

3. Treasure hunt on a line

The treasure hides at a position from 0 to 9. Each guess tells you how far away you are. Teaches abs().

example 3 · press Run, then edit and run again

4. Reaction test

Press Enter as soon as you see GO. Uses time.time() to measure your reaction.

example 4 · press Run, then edit and run again

5. Guess the animal

Three emoji clues, three guesses. Teaches lists of tuples and .lower().

example 5 · press Run, then edit and run again

Ready for something bigger?

These all fit on one screen. The full games on this site take the same ideas further, with boards, word lists and computer players:

Frequently asked questions

What is the simplest game to code in Python?

A guessing game: random.randint for the secret, input() for the guess and an if statement for the answer. It can be done in about 10 lines.

Can I run these simple games without installing Python?

Yes, press Run on this page. They also run unchanged in IDLE or any terminal with Python 3.