Python Forum

Full Version: Not working
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi... I am pulling my hair out trying to figure out why this isn't working. The functions are working fine, but then after running through the functions the value of (name) no longer works.. Bottom line, I'm just wanting it to print (name) at the end. That's it.


def AskForLastName():
	last = input('your last name?')
	print ("Nice meating you.Have a good day")
	
def AskForName():
	name = input('What is your first name:')



	if len(name) >=4:
		print	('hello (:')
		AskForLastName()
		
	elif len(name) <4:
		print('too short. 4 or more charecters')
		AskForName()
		
AskForName()

print (name)
you need to return name from the functions
at end of each function, return what function creates:
for example:
def AskForLastName():
    last = input('your last name?')
    print ("Nice meating you.Have a good day")

    return last
and when calling AskForLastName:
lastname = AskForLastName()
print(lastname)
# or simply:
print(AskForLastName())