im new to python. I tried to search for this issue but all i found is Java discussions.
i need to print out a selection menu like:
bla bla 1
bla bla 2
bla bla 3
i need it to run until the input is within range but i need it to be a function that takes 3 argument (lower_limit, upper_limit, user_input). that way i could call the function and send it the specific limits i need to check each time.
so i run this code:
number_input = input("\nPlease choose a game to play: ")
game_selected = check_input_between_range(1,3,number_input)
to call for the checking function with the 3 arguments (this time the limits are 1 and 3)
def check_input_between_range(lower_limit, upper_limit, user_input):
try:
if lower_limit <= int(user_input) <= upper_limit:
print("user_input is inside the limits")
return user_input
else:
print("input is out of limits\n")
except ValueError:
print("user_input is not int")
except TypeError:
print("user_input is not int")
print("check function finished")
but i cant figure out how to make to loop util the values are within range because if i call the function again in the else:
block it fires up a different instance of the function so in the end it returns a result for each time the loop was run.
maybe im missing something basic here. will appreciate some assistance.
thanks in advance.