Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Not working
#1
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)
Reply
#2
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())
Reply


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020