I'm pretty new to Python and I'm learning about functions at the moment. I have created a simple program that asks the user for some information and then prints it. However, I'm having problems linking the return
variables from one function to the print()
statements in the other function.
This is what I have so far:
def ask_data():
name = input("What's your name?: ")
last_name = input("What's your last name?: ")
age = input("how old are you?: ")
return(name, last_name, age)
def print_data(data):
print("Your name is ", name, last_name)
print("and you are ", age, "years old")
def main():
data = ask_data()
print_data(data)
main()
My problem is that I'm able to enter all the information, meaning that ask_data()
is working. However, when print_data()
is called, I get an error saying the variables name
, last_name
, and age
couldn't be found. How can I link both functions, if that's the issue?