-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRandomNum.py
More file actions
43 lines (29 loc) · 1.02 KB
/
RandomNum.py
File metadata and controls
43 lines (29 loc) · 1.02 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
37
38
39
40
41
42
43
#Python number guessing game
import random
#Set range
lowest_num = 1
highest_num = 100
answer = random.randint(lowest_num,highest_num)
#track random numbers
guesses = 0
is_running = True
print("Python Number Guessing Game")
print(f"Select a number between {lowest_num} and {highest_num}")
while is_running:
guess = input("Enter your guess:")
if guess.isdigit():
guess = int(guess)
guesses +=1
if guess < lowest_num or guess > highest_num:
print("WARNING: Range exeed the parameter")
elif guess < answer:
print("Too low! Try again!")
elif guess > answer:
print("Too high! Try again!")
else:
print(f"CORRECT! The answer was {answer}")
print(f"Number of guesses: {guesses}")
is_running = False
else:
print("Invalud entry")
print(f"Please select a number between {lowest_num} and {highest_num}")