im trying to learn python and wrote this code to check if the user input is a name (containing only of letters and a "space" However if I try to run it and an error occurs, it keeps on telling me "Please enter a valid name" and then asks me to "Please enter your name" but never stops How do I break the second if loop I tried setting valid = true at different places but i cant figure out how to break the loop once its activated
This is my code:
def get_name():
name = input("Please enter your name: ")
valid = True
for x in name:
if not x.isalpha() or x == "":
valid = False
if valid == False:
print("Please enter a valid name.")
get_name
else:
return name
else:
return name
name_checked = get_name()
print(name_checked)
Thanks for any help :)