要求:
  1. 起动程序流程后 ,让用户键入薪水,随后复印产品列表
  2. 容许用户依据商品编号购买商品
  3. 用户挑选产品后,检验余额是不是够 ,不足在线充值,够就立即扣费
  4. 账户余额恰好是0时,立即退出
  5. 可随时随地退出 ,退出时,复印已购买商品和余额
 1 # Author:Zhao
 2 purchased = []
 3 salary = int(input("输入您你的薪水: "))
 4 commodity = [[1,"IPhone",5800],[2,"Mac Pro",12000],[3,"Stacbuck Latte",31],[4,"Alex Python",81],[5,"Bike",800]]
 5 count = 0
 6 Recharge = 0
 7 while count < 1:
 8     for i in commodity:
 9         print(i)
10     num = int(input("输入您你需要选购的商品编号: "))
11     #购买商品的额度
12     amount = commodity[num - 1][2]
13     if salary >= amount:
14         salary = salary - amount
15         purchased.append(commodity[num - 1][1])
16         print("加入购物车已添加:", purchased, "余额还剩:", salary)
17     else:
18             salary2 = amount - salary
19             print("选购",commodity[num -1][1],"产品","还差",salary2,"元,","请在线充值......")
20             salary1 = int(input("输入您在线充值额度: "))
21             salary = salary salary1
22             if salary >= amount :
23                 salary = salary -amount
24                 purchased.append(commodity[num - 1][1])
25                 print("加入购物车已添加:", purchased, "余额还剩:", salary)
26             else:
27                 print("余额不够,购买别的产品吧")
28     count  = 1
29     if count == 1:
30         if salary == 0:
31             print("你的钱夹早已被挖空")
32             break
33     countine_confirm = input("是不是再次买东西:")
34     if countine_confirm !="q" :
35          count =0
36 print("已购买了:",purchased,"余额还剩:",salary)

 



文章来源于网络 ,如有侵权请联系站长QQ61910465删除


微信号:lanceleesir
添加微信好友, 获取更多信息
复制微信号
本文版权归QU快排Www.seoGurubLog.com 所有,如有转发请注明来出,竞价开户托管,seo优化请联系QQ▲61910465