Python入门习题大全——五香烟熏牛肉(pastrami)卖完了

Python入门习题大全——索引

使用为完成练习“熟食店”而创建的列表sandwich_orders,并确保 pastrami 在其中至少出现了三次。在程序开头附近添加这样的代码:打印一条消息,指出熟食店的五香烟熏牛肉卖完了;再使用一个while循环将列表sandwich_orders 中的 pastrami 都删除。确认最终的列表 finished_ sandwiches 中不包含 pastrami。

# 五香烟熏牛肉 (pastrami) 卖完了
sandwich_orders = ['pastrami', 'A', 'pastrami', 'B', 'pastrami', 'C']

while 'pastrami' in sandwich_orders:
    sandwich_orders.remove('pastrami')

print(sandwich_orders)

输出为:

['A', 'B', 'C']
发布了269 篇原创文章 · 获赞 18 · 访问量 3万+

猜你喜欢

转载自blog.csdn.net/qq_43479432/article/details/105421170