题解 | #食堂点餐#
食堂点餐
http://www.nowcoder.com/practice/24a68a70621a4803845304be3304ac5f
NP25 食堂点餐
思路:
创建列表,for循环,按照要求对应输出;同时设置计数器累加;
代码如下:
order_list = ['rice', 'beef', 'chips', 'pizza', 'pizza', 'yogurt', 'tomato', 'rice', 'beef']
count = 0
for i in order_list:
if i == 'pizza':
count += 10
print("pizza is 10 dollars")
elif i == 'rice':
count += 2
print('rice is 2 dollars')
elif i == 'yogurt':
count += 5
print('yogurt is 5 dollars')
else:
count += 8
print('{} is 8 dollars'.format(i))
print(count)