简易购物车系统

shopping_mail = [
  ('Iphone',58000),
  ('Mac Pro',98000),
  ('Bike',8000),
  ('Watch',106000),
  ('Coffee',310),
  ('Alex Python',1200),
]
shopping_cart = []

salary=input("请输入您的工资金额:")
if salary.isdigit():
  salary=int(salary)
  while True:
    for index,item in enumerate(shopping_mail):
      print(index,item)
    enter_number=input("请输入您要购买的商品编号:")
    if enter_number.isdigit():
      enter_number=int(enter_number)
      if enter_number>-1 and enter_number        p_item=shopping_mail[enter_number]
        if p_item[1]<=salary:
          shopping_cart.append(p_item)
          salary-=p_item[1]
          print("您选购的商品金额是:\033[31m%s\033[0m,您的工资余额为:\033[31m%s\033[0m" % (p_item, salary))
        else:
          print("您的余额不足,无法继续购买!")
      else:
         print("您输入的商品编号不存在:")
    elif enter_number=="q":
      print("\033[0;32;40m------您本次购物清单为-------\033[0m")
      for p in shopping_cart:
        print(p)
      print("您的余额为:\033[31m%s\033[0m"%(salary))
      exit()
    else:
        print("\033[31m输入有误,必须输入数字或者正整数!\033[0m")

简易购物车系统_第1张图片

 

你可能感兴趣的:(简易购物车系统)