forked from souravjain540/Basic-Python-Programs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnumber_guessing_game.py
More file actions
32 lines (20 loc) · 810 Bytes
/
number_guessing_game.py
File metadata and controls
32 lines (20 loc) · 810 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# Number guessing
# This is a number guessing game where you will guess the number from 1-100
import random
randno = random.randint(1,100)
guesses = 0
userguess = None
while(userguess!=randno):
try:
userguess = int(input('Guess The Number : \n'))
except:
print("Enter a valid number.") # Checks whether the number is valid or not
if (randno==userguess):
print ("Yayy, you gussed the right number! ")
elif (randno<userguess):
print("Guess the Smaller number")
else:
print("Guess Greater number")
guesses +=1 # Adding the number of guesses; for the total guesses.
print(f"You guessed the number in {guesses} guesses")
print ("This Project was created by Aayush")