>
Code Monsters Academy
Home › Blog › Python games

Three Python Games for Beginners: Guess, Dice and Times Tables

These three programs are the shortest way to a working game. Each one is under 20 lines, uses only the standard library, and prints something on screen immediately.

Guess the number

import random

answer = random.randint(1, 10)
tries = 0
while True:
    guess = int(input("Guess 1-10: "))
    tries += 1
    if guess == answer:
        print("Correct in", tries, "tries!")
        break
    print("Higher" if guess < answer else "Lower")

Sample output

(run it and you will see the prompt printed in the terminal)

Dice roller

import random

rolls = [random.randint(1, 6) for _ in range(5)]
print("Rolls:", rolls)
print("Total:", sum(rolls))

Sample output

(run it and you will see the prompt printed in the terminal)

Multiplication drill

import random

score = 0
for _ in range(5):
    a, b = random.randint(2, 9), random.randint(2, 9)
    if int(input(f"{a} x {b} = ")) == a * b:
        score += 1
print("You got", score, "out of 5")

Sample output

(run it and you will see the prompt printed in the terminal)

Common mistakes

Variations to try

More Python games

Overview of the whole set: Python games code to copy and paste.

If you prefer learning by playing, Code Monsters Academy teaches the same ideas one level at a time.