DEV Community

Cover image for Cool Python Project 2: Guess that Number Game
Abhi Develops - SunTech
Abhi Develops - SunTech

Posted on

2 3

Cool Python Project 2: Guess that Number Game

Hi Everyone! Welcome to Cool Python Projects!
In this post I will be showing you how to make a Guess that Number Game in Python. Please remember to follow me to stay updated on any new projects.

import random

print("I have thought of a number between 1 and 10. But I will not tell you, you have to guess it.")

the_number = random.randint(1, 10)

username = input("What is your name? ")

if username == 'Abhinav Gupta':

   print("Hello Abhinav Gupta, my name is Alexa.")

user_int = -1

while user_int != the_number:

   user_input = input("Guess a number between 1 and 10. ")

   user_int = int(user_input)

   if user_int > the_number:

       print('Oh No {0}, Your guess {1} is too high!'.format(username, user_int))

   elif user_int < the_number:

       print('Uh Oh, {0} Your guess {1} is to small!'.format(username, user_int))

   else:

       print("YOU GOT IT, WELL DONE!")

print("Well Done, take rest now.")
Enter fullscreen mode Exit fullscreen mode

I hope you enjoyed this Python project.

All the projects code in the series

AWS Q Developer image

Your AI Code Assistant

Automate your code reviews. Catch bugs before your coworkers. Fix security issues in your code. Built to handle large projects, Amazon Q Developer works alongside you from idea to production code.

Get started free in your IDE

Top comments (0)

Billboard image

Create up to 10 Postgres Databases on Neon's free plan.

If you're starting a new project, Neon has got your databases covered. No credit cards. No trials. No getting in your way.

Try Neon for Free →