+ 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 + "?")
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 + "?")
+ 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 + "?")
+ 4
thank you bouth!
- 4
Did you tried to say please to your code? 😐