mini购物车程序

product_list=[("Iphohe",5800),("Mac Pro Book",12900),
("xiaomi 4c",1200),("Alex python",120),
("Bike",800)]
shopping_list=[]
salary=input("input your salary:")
if salary.isdigit():
salary=int(salary)
else:
print("您的输入有误,请重新输入")

while True:
for index,shangpin in enumerate(product_list):
print(index,shangpin)

user_choice=input("选择要买啥?>>>")
if user_choice.isdigit():
user_choice=int(user_choice)
if user_choice<len(product_list) and user_choice>=0:
p_item=product_list[user_choice]
if p_item[1]<= salary: #买得起
shopping_list.append(p_item)
salary-=p_item[1]
print("Added %s into shopping cart,your current balance is \033[32;1m%s\033[0m"%(p_item,salary))
else:
print("your current balance is\033[31;1m%s\033[0m,信仰不足,请充值"%(salary))
elif user_choice=='q':
       print('______shopping list______')
       for a in shopping_list:
       print(a)
print("your current balance is\033[31;1m%s\033[0m,谢谢使用"%(salary) )
exit()
else:
print("invalid option")
posted @ 2018-05-01 13:40  wan了个蛋  阅读(248)  评论(0编辑  收藏  举报