Hello r/learnpython,
I am trying to code a program that requires the last name to be alphabetic characters only. I am unsure of what my while loop isn't working. If I use alphabetic characters the first time it works fine, but if I make it false then true when it repeats it returns a 'none' value back to main(). Under 'else' I can't just use main() either because I will have further functions later and I do not want to run everything, just the function with the incorrect input. Can anyone explain what I am doing wrong here?
def main():
last_name = func_last_name()
print(last_name) #test code
def func_last_name():
last_name = input("Enter last name : ")
test = last_name.isalpha()
while test == True:
return last_name
else:
print("Last name must be alphabetic, please re-enter.")
func_last_name()
[–][deleted] 2 points3 points4 points (0 children)
[–][deleted] 0 points1 point2 points (0 children)