I am writing a simple guessing number program and I want to use functions for different sections of the code. The first function decides on the range the user will guess between. I want to carry the value of user_input into the next function. The only way I know is to make user_input a global variable. Just wondering is there a better way of achieving this than making the variable global?
def decide_range():
flag = True
while flag:
global user_input
user_input = input("Enter a value for range ")
if user_input.isdigit():
user_input = int(user_input)
if user_input < 2:
print("Number must be 2 or greater to play this game")
continue
print(f"You have entered {user_input}")
flag = False
else:
print("Not a valid integer")
def guess_Number():
print("Guess a number between 1 and",user_input)