Hi everybody,
I'm trying to write a function that takes in 2 values, a min and a max, that prompts the user to enter a value within that range, and uses 0 as a sentinel to quit the loop.
My issue is, I also want the loop to continue prompting the user when the user enters nothing (i.e. hits enter) until a value between the range is entered. How do I go about doing this with the code I have already written? Thanks!
def getValidNum(min, max):
QUESTION = "Enter a value, 0 to quit: "
num = input(QUESTION)
while num != 0:
if num in range(min, max + 1):
return num
else:
print("Sorry %d - %d or 0 only") % min, max
print("Try again.")
num = input(QUESTION)