I am working on input validation to validate integer input and index range. My def inputNumber(message) function works as I use it in other areas of my program and it functions as expected. However, my def withinRange(myList, choice) function throws an error appropriately but I get stuck in an endless loop. My code is provided below any help or suggestions are appreciated in advance.
def inputNumber(message): #input validation to ensure user enters a number while True: try: userInput = int(input(message)) except ValueError: print('That is not a number! Try Again!') continue else: return userInput break def withinRange(myList, choice): while True: try: result = myList[choice-1] except IndexError: print('That number is not a valid choice! Try Again!') continue else: return result break
choice = withinRange(resultsList,inputNumber('Select your new username by entering the number above:\n'))