购物车练习

 
 
  • product_list = [("Iphone",8800), ("《中国药典》",2200),("MAC",200),("台灯",176),("字典",127)]
  • print("---------商品清单---------")
  • print(product_list)
  • print("当您购物结束请输入e结束")
  • shopping_cart=[]
  • while True:
  •     salary=input("请输入现有资金:")
  •     if salary.isdigit():
  •         salary=int(salary)
  •         while True:
  •             choose=input("请输入商品序号")
  •             if choose.isdigit():
  •                 choose=int(choose)
  •                 if choose>=0 and choose<len(product_list):
  •                     if salary>=product_list[choose][1]:
  •                         shopping_cart.append(product_list[choose])
  •                         cart_list=product_list[choose]
  •                         salary-=product_list[choose][1]
  •                         print("%s 已加入购物车"%(product_list[choose][0]))
  •                         print("当前余额为 %s"%(salary))
  •                     else:
  •                         print("提示!您的资金不足")
  •                 else:
  •                     print("您所选择的商品不存在,请选择其他商品")
  •             elif choose=="e":
  •                 print("--------购物清单 --------")
  •                 print(shopping_cart)
  •                 print("您的余额为:")
  •                 print(salary)
  •                 exit()
  •             else:
  •                 print("提示!您所输入的格式不正确,请重新输入")
  •     else:
  •         print("提示!您所输入的格式不正确,请重新输入")

猜你喜欢

转载自blog.csdn.net/qq_42111985/article/details/80285539