购物提示例子

 1 choice_list = []
 2 product_list = [["Iphone",5800],["bike",1500],["watch",800],["pcdell",4000],["door",3500]]
 3 while True:
 4     salary = input("请输入你的工资:")
 5 
 6     if salary.isdigit():
 7         salary = int(salary)
 8         while True:
 9             for index,product in enumerate(product_list):
10                 print(index,product)
11             user_choice = input("请输入你购买的商品编号:")
12             if user_choice.isdigit():
13                 user_choice = int(user_choice)
14                 if user_choice < len(product_list) and user_choice >= 0:
15 
16                     user_choice_p = product_list[user_choice]
17                     if salary > user_choice_p[1]:
18                         choice_list.append(user_choice_p)
19                         salary -= user_choice_p[1]
20                         print("你的购物车里添加了商品:{_product}".format(_product = user_choice_p[0]))
21                         print("你的购物卡余额还有{_salary}元".format(_salary = salary))
22                     else:
23                         print("你的金额不足!请选择其他商品!")
24 
25                 else:
26                     print("你输入的商品编号不存在!请重新输入!")
27 
28             elif user_choice == "q":
29                 print("******************你购买的商品如下**********************")
30                 for user_choice_list in choice_list:
31                     print(user_choice_list)
32                 exit()
33             else:
34                         print("你输入的商品编号有误!请重新输入。。。。。")
35     else:
36         print("你输入的工资有误,请重新输入")

 

转载于:https://www.cnblogs.com/bozaizai/p/8690973.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值