Super Simple Python: High Low Guessing Game

Super Simple Python is a series dedicated to creating super simple Python projects for beginners to be able to do in under 15 minutes. In this episode, we’ll be covering how to build a high low guessing game in under 15 lines of code!

For a video version see:

Like many of the projects we’ve built in the Super Simple Python series like the Random Number Generator, the Dice Roll Simulator, and Rock Paper Scissors, the High Low guessing game is built around random number generation. In this game, the computer will generate a number and ask us for guesses. For each turn of the game, we’ll guess a number. The computer will tell us if our number is too high or too low until we guess the correct number.

Picking a Random Number to Guess

Since we’re working with a random number, we’ll need to start off by importing our random library. After that we’ll also print out a sentence telling the user what the range of our random number will be in, and then set a random number. For this high low guessing game, we’ll pick a random number between 1 and 100 to guess.

import random
 
print("This program picks a random number between 1 and 100 and tells you if your guess is high or low until you guess it")
num = random.randint(1, 100)

Playing the High Low Guessing Game

Alright, now that we’ve picked a number between 1 and 100 to guess, it’s time to play the guessing game. We’ll start by declaring a variable, guessing, and setting it to True. This tells the program whether or not we’re still trying to guess the number. While guessing is True, we’ll ask the user for their guess. If the guess is greater than the number, we’ll tell the user their guess was too high. If the guess is less than the number, we’ll tell the user their guess was too low. Otherwise they’ve guessed the number and we should tell them that they got it and set guessing to False so the while loop doesn’t repeat.

guessing = True
while guessing:
    guess = int(input("What is your guess? "))
    if guess > num:
        print("Too high!")
    elif guess < num:
        print("Too low!")
    else:
        print("Nice, you got it!")
        guessing = False

Once we run our program we should get an output like the image below.

To play around with this code, try picking a different range of numbers to guess from. Other augmentations to the high low guessing game could include telling the user they’re “way too high” or “way too low” when their guess is more than some number x away from the target, or telling the user if they’re getting warmer or colder from their last guess. Have fun!

Further Reading

Learn More

To learn more, feel free to reach out to me @yujian_tang on Twitter, connect with me on LinkedIn, and join our Discord. Remember to follow the blog to stay updated with cool Python projects and ways to level up your Software and Python skills! If you liked this article, please Tweet it, share it on LinkedIn, or tell your friends!

I run this site to help you and others like you find cool projects and practice software skills. If this is helpful for you and you enjoy your ad free site, please help fund this site by donating below! If you can’t donate right now, please think of us next time.

Yujian Tang
Yujian Tang

I started my professional software career interning for IBM in high school after winning ACSL two years in a row. I got into AI/ML in college where I published a first author paper to IEEE Big Data. After college I worked on the AutoML infrastructure at Amazon before leaving to work in startups. I believe I create the highest quality software content so that’s what I’m doing now. Drop a comment to let me know!

One-Time
Monthly
Yearly

Make a one-time donation

Make a monthly donation

Make a yearly donation

Choose an amount

$5.00
$15.00
$100.00
$5.00
$15.00
$100.00
$5.00
$15.00
$100.00

Or enter a custom amount

$

Your contribution is appreciated.

Your contribution is appreciated.

Your contribution is appreciated.

DonateDonate monthlyDonate yearly

4 thoughts on “Super Simple Python: High Low Guessing Game

Leave a Reply

%d bloggers like this: