I'm trying to return a list my_list
created within function make_list
to use in the function print_elems
.
I keep getting the error
my_list is not defined
for when I ask to print it, after calling "make_list".
What am I doing incorrectly in trying to return "my_list"?
def make_list():
my_list = []
print("Enter \"-999\" to return list.")
x = int(input("Enter a number: "))
while x != -999:
my_list.append(x)
x = int(input("Enter a number: "))
return my_list
def print_elems(user_list):
print(user_list, sep=' ')
make_list()
print(my_list)
print_elems(my_list)