Python Number Guessing Game mini Project

Number Guessing Game in Python with Source Code

Now we are going to create a simple number guessing game project in python. For this mini-project, we have to import a python package called random then we will use randint() module to generate a random integer number. Randint module will take the argument as a range of numbers. 

Syntax:

import random
random.randint(range of number)
 

Number Guessing Game Source Code Download

import random

gen_ran_no = random.randint(0,100)

user_no = int(input('Enter Guessing number: '))

if user_no == gen_ran_no:

print("YOU WIN THE GAME")

else:

if user_no > gen_ran_no:

print('your number is greater')

else:

if user_no < gen_ran_no:

print('you number is smaller')

print('Your Real number was:',gen_ran_no)

Output:

C:\Users\Pramod\PycharmProjects\pythonProject\venv\Scripts\python.exe C:/Users/Pramod/PycharmProjects/pythonProject/main.py
Enter Guessing number: 22
you number is smaller
Your Real number was: 50

Process finished with exit code 0

How do you Generate Random Numbers in Python?

First we have to import package called random then #use randint() module to generate randam integer number. Example is given below:
import random
gen_ran_no = random.randint(0,100)
print(gen_ran_no)

How do you Play the Number Guessing Game?

Just simply enter any number randomly, if that number is equal to that number which is generated by the program then you will be the Winner otherwise it will show that your number smaller or greater, and last it will also show you what was the number generated by the program.

Recommended Post:

Get Salesforce Answers

Pramod Kumar Yadav is from Janakpur Dham, Nepal. He was born on December 23, 1994, and has one elder brother and two elder sisters. He completed his education at various schools and colleges in Nepal and completed a degree in Computer Science Engineering from MITS in Andhra Pradesh, India. Pramod has worked as the owner of RC Educational Foundation Pvt Ltd, a teacher, and an Educational Consultant, and is currently working as an Engineer and Digital Marketer.



Leave a Comment