Number Guessing Game in Python with Source Code
Syntax:
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:
- Python Hello World Program
- Python Comment | Creating a Comment | multiline comment | example
- Python Dictionary Introduction | Why to use dictionary | with example
- How to do Sum or Addition in python
- Python Reverse number
- find the common number in python
- addition of number using for loop and providing user input data in python
- Python Count char in String
- Python Last Character from String
- Python Odd and Even | if the condition
- Python Greater or equal number
- Python PALINDROME NUMBER
- Python FIBONACCI SERIES
- Python Dictionary | Items method | Definition and usage
- Python Dictionary | Add data, POP, pop item, update method
- Python Dictionary | update() method
- Delete statement, Looping in the list In Python
- Odd and Even using Append in python
- Python | Simple Odd and Even number
Get Salesforce Answers