码迷,mamicode.com
首页 > 其他好文 > 详细

购物车

时间:2018-08-22 14:57:56      阅读:96      评论:0      收藏:0      [点我收藏+]

标签:tin   git   [1]   for   []   index   col   ack   pre   

shopping=[(‘toy‘,50),
(‘clothes‘,100),
(‘iphone‘,5000),
(‘bike‘,400),
(‘hat‘,20),
(‘food‘,100)]
buy_shopping=[]
salary=int(input(‘input your salary:‘))
while True:
for index,item in enumerate(shopping):
print(index,item)
choice_num = input(‘input your miss choice shopping num:‘)
if choice_num.isdigit():
choice_num = int(choice_num)
if choice_num<len(shopping) and choice_num>=0:
choice_shopping=shopping[choice_num]
if choice_shopping[1]<=salary:
salary -= choice_shopping[1]
print(‘buy shopping:‘,choice_shopping[0])
print(‘balance:‘,salary)
else :
print(‘your money not enough,again choice:‘)
break
else:
continue
buy_shopping.append(choice_shopping[0])
for p in buy_shopping:
print(‘your buy shoping is:‘,p)

购物车

标签:tin   git   [1]   for   []   index   col   ack   pre   

原文地址:https://www.cnblogs.com/0429yang/p/9517263.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!