【发布时间】:2020-10-09 22:30:28
【问题描述】:
shoppingList = [('Carrot',2), ('Onion',1), ('Tomato',3)]
amountGiven = 12
for item, price in shoppingList:
openMenu = True
while openMenu:
costumerPick = input('Please choose item from the shoppingList\n')
if costumerPick == 'Carrot':
print('That would be: ${}'.format(price))
amountGiven = amountGiven - price
elif costumerPick == 'Onion':
print('That would be: ${}'.format(price))
amountGiven = amountGiven -price
elif costumerPick == 'Tomato':
print('That would be: ${}'.format(price))
amountGiven = amountGiven - price
我想在客户选择这些选项之一后打破循环
【问题讨论】:
-
鉴于您的问题的标题,您显然知道
break是打破循环的方法。所以,既然你已经知道如何去做你所问的——你的真正问题是什么? -
我们希望您在此处发布之前进行适当的研究,例如搜索您的问题标题。请参阅任何有关循环的教程;注意
break声明。 -
我的问题是我应该在哪里使用 break 命令来结束循环?
标签: python python-3.x while-loop