-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRandomNum.py
More file actions
36 lines (31 loc) · 1.12 KB
/
RandomNum.py
File metadata and controls
36 lines (31 loc) · 1.12 KB
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
33
34
35
36
#Python number guessing game using random module
import random
low = 1
high = 100
guesses = 0
number = random.randint(low,high)
is_Running = True
print("PYTHON NUMBER GUESSING GAME")
if_True = input("Do you want to play this game (Y/N): ")
if if_True.lower() == 'y':
while is_Running:
guess = input(f"Enter your guess between {low} and {high}: ")
if guess.isdigit():
guess = int(guess)
guesses +=1
if guess < low or guess > high:
print("That number is out of range.")
print(f"Please select a number between {low} and {high}: ")
elif guess < number:
print("Too low! Try again!")
elif guess > number:
print("Too High! Try Again!")
else:
print(f"Correct guess! The answer was {number}")
print(f"Number of guesses: {guesses}")
is_Running = False
else:
print("Invalid Guess.")
print(f"Please select a number between {low} and {high}: ")
else:
print("OK :((")