product_list = [
("phone",6000),
("cup",80),
("coffee",30),
("computer",5000),
("tee",20),
] #定义商品列表
shoppint_list = [] #定义购物车
salary = input("input you salay:") #定义工资
if salary.isdigit(): #判断是不是整数
salary = int(salary)
while True:
for item in enumerate(product_list):#取下标,商品编码
print(item)

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: #获取产品的价格<工资
shoppint_list.append(p_item) #把产品加入购物车
salary -= p_item[1]
print(" %s 已经加入购物车,现在的余额是 \033[31;1m%s\033[0m" %(p_item,salary))
else:
print("你的余额不足")

elif user_choice == "q":
print('----------shopping_list----------')
for p in shoppint_list:
print(p)
print("余额",salary)
exit()
else:
print("invalid option")
posted on 2018-07-06 11:12  owl兮泷  阅读(108)  评论(0编辑  收藏  举报