+ 2

Question: why is it not printing the last part? I am using python. Can you help me?

def start(): print("Hello {}!".format(get_name())) def get_name(): name = input("What is your name?") return name if __name__ == "__main__": start() print("What now" + name + "?")

9th Oct 2018, 9:16 AM
FlaviusKID
FlaviusKID - avatar
4 odpowiedzi
+ 4
The variable "name" lives only inside the function get_name(), it doesn't exists outside. There are multiple ways to fix it. Here's one: def start(): print("Hello {}!".format(name)) def get_name(): return input("What is your name?") name = get_name() if __name__ == "__main__": start() print("What now " + name + "?")
9th Oct 2018, 9:40 AM
Kishalaya Saha
Kishalaya Saha - avatar
+ 4
Or just for make all more logic: def hello(name): print("Hello {}!".format(name)) def get_name(): return input("What is your name?") if __name__ == "__main__": name= get_name() hello(name) print("What now " + name + "?")
9th Oct 2018, 9:57 AM
KrOW
KrOW - avatar
+ 4
thank you bouth!
9th Oct 2018, 10:32 AM
FlaviusKID
FlaviusKID - avatar
- 4
Did you tried to say please to your code? 😐
9th Oct 2018, 11:28 AM
Yagshygeldi Annagurdow