I keep on trying to get the data from the function to display in the list, I’ve tried using list.append
but I keep on getting errors, what am I doing wrong?
JavaScript
x
14
14
1
def pick_up():
2
name=input("Good Afternoon, who would you like to pick up? ")
3
additional_student=input(f"Is {name} the only person you want to pick up ?YES/NO")
4
if additional_student == "Yes":
5
print(f"Please wait, {name} would be with you shortly")
6
else:
7
name_2=input("Who else would you like to pick? ")
8
print(f"Please wait, {name} and {name_2} would be with you shortly.")
9
10
pick = pick_up()
11
picked_students.append(pick)
12
print(picked_students)
13
pick_up()
14
Advertisement
Answer
Your pick_up()
function needs to return something. Since it can return either one or two students, you probably want it to return a list of either one or two students, and extend
your picked_students
list with that list.
JavaScript
1
16
16
1
def pick_up():
2
name=input("Good Afternoon, who would you like to pick up? ")
3
additional_student=input(f"Is {name} the only person you want to pick up ?YES/NO")
4
if additional_student == "Yes":
5
print(f"Please wait, {name} would be with you shortly")
6
return [name]
7
8
name_2=input("Who else would you like to pick? ")
9
print(f"Please wait, {name} and {name_2} would be with you shortly.")
10
return [name, name_2]
11
12
picked_students = []
13
pick = pick_up()
14
picked_students.extend(pick)
15
print(picked_students)
16