I'm trying to set up a function that has the user input their name and then confirm their name is correct before continuing. If the name is not correct I want them to be able to go back in and change their name. but I can't figure out how to return the name to the global. I've played around with what seems like a million different ways, but these are the two most recent ways I've tried....
def assign_name():
name = input("What is your name? ")
confirm = input(f"is {name} correct? Y/N")
if confirm != 'y':
assign_name()
else:
print(name) ### tester
return name
my_name = assign_name()
print(my_name) ### tester
################################
def assign_name(name):
confirm = input(f"is {name} your name? Y/N")
if confirm != 'y':
assign_name(input("What is your name?"))
else:
print(name) ### tester
return(name)
my_name = assign_name(input("What is your name?"))