import sys values = (10, 20, 30, 40, 50) #pos = input("Get the value at which position? ") #pos = int(pos) try: pos = int(input("Get the value at which position? ")) except ValueError: print("Position must be an integer.") sys.exit() #if the position is invalid, ask until it is valid while pos < 0 or pos >= 5: #while pos >= 5 or pos < 0: print("Position must be between 0 and 4 inclusive.") pos = int(input("Get the value at which position? ")) if pos < 5 and pos >= 0: value = values[pos] print("The value at that position is", value)