I'm trying to learn how to do user input validation and build off this post How to return a specific point after an error in 'while' loop
I believe the issue is when current_answer is evaluated against the answer list. Regardless of what I enter for a number, the 'else' statement kicks in.
def input_validator(question, answers):
while True:
current_answer = input(question)
if current_answer in answers:
print('Success')
break
print ('Failure')
return current_answer
inputQuarter = input_validator('What quarter is being processed (1,2,3,4)?: ', [1,2,3,4] )
I'm assuming the problem lies with something I don't understand about breaking the for loop because the if/else statement seems to work fine outside of the loop.