I am trying to ensure that whenever the user inputs a value, it is a letter. I created a function, which seems to work fine, when debugging, but the user_input is not returning the correct value in the function. It returns the invalid value that was entered into the function. Do I need to create a new variable in this function and return it instead? Or is there a better way to validate that an input is a letter. I've read about Value exception, but I thought this way would work fine as well.
def validate_input(user_input):
while True:
if user_input.isalpha():
return False
else:
user_input = input("invalid selection, try again ")
user_guess = input("What is your guess? ")
validate_input(user_guess)
If there is a more efficient way, or a better Pythonic way, to do this, please let me know. Thanks in advance.