购物车小程序

时间:2018-08-31 19:18:01   收藏:0   阅读:198
product_list = [
(‘Iphone‘,5800),
(‘Mac Pro‘,9800),
(‘Bike‘,800),
(‘Watch‘,10600),
(‘Coffee‘,31),
(‘Alex Python‘,120)
]
shop_dist=[]
salary=input(" inpue your salary")
if salary.isdigit():
salary=int(salary)
while True:
for index,item in enumerate(product_list):
print(index,item)
user_chose=input("you yao mai ma?")
if user_chose.isdigit():
user_chose=int(user_chose)
if user_chose<len(product_list) and user_chose>0:
pie_list = product_list[user_chose]
if pie_list[1]<=salary:
print("买得起")
shop_dist.append(pie_list)
salary -= pie_list[1]
print(" add %s your pie_list and your salayy is \033[31;1m%s\033[0m" % (pie_list, salary) )
else:
print(‘就剩这点%s钱,买个毛线啊‘% salary)
else:print("ni输入的%s商品不存在" % user_chose)
elif user_chose ==‘q‘:
print(‘----------------你的购物车--------------‘)
for i in shop_dist:
print(i)
print("Your current balance:", salary)
exit()
else:
print(‘invald option‘)
评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!