I am having trouble passing a variable from one function to another:
def name():
first_name=input("What is your name? ")
if len(first_name)==0:
print("\nYou did not enter a name!")
return name()
else:
print("\nHello %s." % first_name)
return surname()
def surname():
last_name=input("\nCan you tell my your last name please?")
if len(last_name)==0:
print("\nYou did not enter a last name!")
return surname()
else:
print("Nice to meet you %s %s." % (first_name,last_name))
I want the last command to print the inputed first_name from def name() and last name from def surname()
I always get the error that first_name is not defined and I do not know how to import it from the first function. The error I get is:
print("Nice to meet you %s %s." % (first_name,last_name))
NameError: name 'first_name' is not defined
What am I doing wrong?
surnamefunction to besurname(first_name)and call it withreturn surname(first_name)