有没有办法将数据从函数传输到列表中?

Is there a way to tranfer data from a function into a list?

我一直在尝试从函数中获取数据以显示在列表中,我已经尝试使用 list.append 但我一直出错,我做错了什么?

def pick_up():
        name=input("Good Afternoon, who would you like to pick up? ")
        additional_student=input(f"Is {name} the only person you want to pick up ?YES/NO")
        if additional_student == "Yes":
            print(f"Please wait, {name} would be with you shortly")
        else:
            name_2=input("Who else would you like to pick? ")
            print(f"Please wait, {name} and {name_2} would be with you shortly.")

pick = pick_up()
picked_students.append(pick)
print(picked_students)
pick_up()

您的 pick_up() 函数需要 return 一些东西。由于它可以 return 一个或两个学生,您可能希望它 return 一个或两个学生的列表,以及 extend 您的 picked_students 列表和该列表。

def pick_up():
    name=input("Good Afternoon, who would you like to pick up? ")
    additional_student=input(f"Is {name} the only person you want to pick up ?YES/NO")
    if additional_student == "Yes":
        print(f"Please wait, {name} would be with you shortly")
        return [name]
    
    name_2=input("Who else would you like to pick? ")
    print(f"Please wait, {name} and {name_2} would be with you shortly.")
    return [name, name_2]

picked_students = []
pick = pick_up()
picked_students.extend(pick)
print(picked_students)