题解 | #食堂点餐#
食堂点餐
http://www.nowcoder.com/practice/24a68a70621a4803845304be3304ac5f
创建订单记录
order_list = ['rice', 'beef', 'chips', 'pizza', 'pizza', 'yogurt', 'tomato', 'rice', 'beef']
初始化总计金额
total = 0
创建函数order_handle以供后续复用
def order_handle(f_name, price):
global total
total += price
print('%s is %s dollars' % (f_name, price))
进行点餐记录的判断与总计金额打印
for i in order_list:
if i == 'rice':
order_handle('rice', 2)
elif i == 'beef':
order_handle('beef', 8)
elif i == 'chips':
order_handle('chips', 8)
elif i == 'pizza':
order_handle('pizza', 10)
elif i == 'yogurt':
order_handle('yogurt', 5)
else:
order_handle('tomato', 8)
print(total)