I'm trying to make a simple control in Python 2 to make sure that the user's input is smaller than a given constant. If this is not the case it should ask again for another integer until it is smaller.
limit_store = 12
def input_store():
sel_store = int(raw_input("Which store do you want? "))
if sel_store > limit_store:
print "Store number %i is not valid" % sel_store
input_store()
return sel_store
store = input_store()
This worked the first time I wrote it in an Ipython notebook. Now if the first input is 9, it returns 9 as expected. If the input is 999, which is larger than 12, the if statement is runned and we get to select another integer. Selecting a correct input after a wrong one will return the old wrong input instead of the newer input.
return input_store(), the value ofsel_storewill be stored on the first call to the function so if you enter 100 different numbers you will always get the first unless you return