-
Notifications
You must be signed in to change notification settings - Fork 0
/
Guess The Number.py
36 lines (32 loc) · 1006 Bytes
/
Guess The Number.py
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
import random
import sys
def x_randomiser():
x = random.randrange(1, 100, 1, int)
return x
def random_guesser ():
global x
user_guess = input("Input an integer between 1-100:\n")
if user_guess.isdigit():
user_guess = int(user_guess)
if user_guess == x:
print("Well done! The answer was indeed %d!" % x)
rerun = input("Do you want to play again? <Y/N>\n")
if rerun == "Y":
x = x_randomiser()
random_guesser()
else:
sys.exit()
elif user_guess < x:
print("No, that's too low! Try again.")
random_guesser()
elif user_guess > x:
print("No, that's too high! Try again.")
random_guesser()
else:
print('Try again...\n')
random_guesser()
else:
print("I said an integer!\n")
random_guesser()
x = x_randomiser()
random_guesser()