索引错误,从空列表中弹出

时间:2019-04-23 16:21:09

标签: python-3.x

sandwich_orders = [ 'wrap','toast' ,'regular veg' , 'cheese_toast' , 'cheese_veg', 'big cheese toast' , 'big cheese veg']
finished_sandwiches = []
current_active = True

while current_active:

    current_sandwich = sandwich_orders.pop(0)

    print("\nVerifying your order, " + current_sandwich.title())
    finished_sandwiches.append(current_sandwich)

print("These are your finished sandwiches")
for finished_sandwich in finished_sandwiches:
    print ("\nHere  is your sandwich " + finished_sandwich.title())

1 个答案:

答案 0 :(得分:0)

这是一个无限循环,可以通过在列表为空时停止来解决。 为此,只需在sandwich_orders的大小为0时将current_active设置为False。