|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
代码:
sandwich_orders = ['apple', 'pastrami', 'pear', 'pastrami', 'water', 'pastrami']
finished_sandwiches =[]
print("Sorry, we dont't have pastrami")
print(sandwich_orders)
while sandwich_orders:
if 'pastrami' in sandwich_orders:
sandwich_orders.remove('pastrami')
sandwich_order = sandwich_orders.pop()
print('I made your tuna sandwich ' + sandwich_order)
finished_sandwiches.append(sandwich_order)
print("\nFinish sandwich: ")
for finished_sandwiche in finished_sandwiches:
print(finished_sandwiche)
运行结果:
Sorry, we dont't have pastrami
['apple', 'pastrami', 'pear', 'pastrami', 'water', 'pastrami']
I made your tuna sandwich pastrami
I made your tuna sandwich water
I made your tuna sandwich pear
I made your tuna sandwich apple
Finish sandwich:
pastrami
water
pear
apple
想要是实现的效果是 sandwich_orders 列表中的 'pastrami'都删除,finished_sandwiches列表中不包含 'pastrami' |
|