购物车

product_list = [
('iphone6s',5800),
('kindle',800),
('tesla', 900000),
('python book', 105),
('bike',2000),
]

wages = input('请输入工资:')
a = []

if wages.isdecimal():
wages=int(wages)
while True:
#打印商品
for i,v in enumerate(product_list,1):
print(i,'>>>>>',v)

commodity = input('选择商品编号[退出:q]:')

if commodity.isdecimal():
commodity=int(commodity)

if commodity > 0 and commodity <= len(product_list):
a_name = product_list[commodity-1]
if a_name[1]<wages:
wages-=a_name[1]
a.append(a_name)
else:
print('余额不足,还剩%s'%wages)
print(wages)


else:
print('编码不存在')
elif commodity == 'q':
print('----------您购买如下商品----------')
tag = 0
for i in a:
t = a.count(i)
if t > 1:
tag +=1
if tag > 1 and tag < t:
continue
elif tag ==t:
tag = 0
continue
else:
print(i,'X%d'%t)



print('您还剩余%s' % wages)
break

else:
print("错误de ")
posted @ 2018-01-19 15:59  阿狸灬控丶  阅读(75)  评论(0)    收藏  举报