I need to generate a random number via a function, return it to another function and then run that second function multiple times with the same random number I got in the first place. But the random number generator makes a new one whenever my function summons it for the random number. (Python3.7)
import random
from sys import exit
def rand():
n = random.randint(1, 1001)
return n
n = rand()
def isdigit(s):
try:
float(s)
return True
except ValueError:
return False
def guess():
g = input("> ")
if isdigit(g):
return int(g)
elif not isdigit(g):
print("\tPlease enter a number.")
guess()
def islower():
print("\tThe number is GREATER than that!")
process()
def ishigher():
print("\tThe number is SMALLER than that!")
process()
def gotit():
print(f"\tCongratulations! You got it! The number was {n}.")
print("\tPlay another hand? y/n")
again = input("> ")
if again == "y":
newgame()
elif again == "n":
print("\tHave fun!")
exit(0)
def process():
g = guess()
if g > n:
ishigher()
elif g < n:
islower()
elif g == n:
gotit()
def newgame():
print("\tI have chosen my number. Start!")
process()
newgame()