购物车代码


product_list=[
('iphone',5000),
('car',500400),
('book',50),
('bicycle',500),
('computer',22200),
]
shop_car=[]
money= input('how much money you have :')
if money.isdigit():
money=int(money)
while True:
for i,j in enumerate(product_list,1):
print(i,j)
chioce=input('chioce the first number you want buy[quit/q]:')
if chioce.isdigit():
chioce=int(chioce)
if chioce>0 and chioce <= len(product_list):
print(product_list[chioce-1])
money -=product_list[chioce-1][1]
shop_car.append(product_list[chioce-1])
else:
print('the chioce not chunzai')
elif chioce=='q':
print('-----the shop list-----')
for v in shop_car:
print(v)
print('you money have %s yuan'%money)
break
else:
print('invilid number')
posted @ 2019-08-19 15:35  ComeIntoBud  阅读(638)  评论(0)    收藏  举报