7-8 熟食店 创建一个名为sandwich_orders 的列表,在其中包含各种三明治的名字,在创建一个名为 finished_sandwiches 的空列表。遍历列表sandwich_orders,对于其中的每种三明治,都打印一条消息,如 I made your tuna sandwich,并将其移到列表 finished_sandwiches中。所有三明治都制作好后,打印一条消息,将这些三明治列出来。
sandwich_orders = ['鸡排三明治','水果三明治','蔬菜三明治']
finished_sandwiches = []
while sandwich_orders:
finished = sandwich_orders.pop()
finished_sandwiches.append(finished)
print(finished_sandwiches)
for sanmingzhi in finished_sandwiches:
print(f"我为你做了{sanmingzhi}")
输出:
['蔬菜三明治', '水果三明治', '鸡排三明治']
我为你做了蔬菜三明治
我为你做了水果三明治
我为你做了鸡排三明治
练习7-9 五项烟熏牛肉卖完了 使用上面的列表,并确保'pastrami'在其中至少出现了三次。在程序的开头附加添加这样的代码:打印一条消息,指出熟食店的五香烟熏牛肉卖完了;再使用一个while循环将列表中的'pastrami'都删除。确认最终的列表finished_sandwiches 未包含’pasteami‘
print("五香烟熏牛肉卖完了。")
beafes = ['五