product = [('羽绒服',200),('毛衣',80),('衬衫',50),('牛仔裤',120),('t恤',55),('苹果笔记本',8000)]shop_car = []print ("欢迎来到购物商城!".center(50,'-'))salary = 5000print ("您好,您的账户余额为:\033[32;1m[%s]\033[0m元,如需充值请输入p,继续购物请输入j:"% salary)t = Falsewhile not t: choice = input() if choice == 'p': salary_add = (input("请输入您需要充值的金额:")) if salary_add.isdecimal(): salary += int(salary_add) print ("您好,您的账户余额为:\033[32;1m[%s]\033[0m元,如需充值请输入p,继续购物请输入j:"% salary) else: print ("请输入正确的充值金额!") elif choice == 'j': t = True else: print ("请输入正确的选项!")y = False while not y: print ("商品列表".center(50,'-')) #打印商品列表 for item in enumerate(product): index = item[0] p_name = item[1][0] p_price = item[1][1] print (index,'.',p_name,p_price) user_choice = input("退出请输入q,查看已购买商品请输入c,请输入序号选择您想要购买的商品:") if user_choice.isdecimal(): #判断用户输入的是否是数字 user_choice = int(user_choice) if user_choice < len(product): #判断商品序号是否存在 p_item = product[user_choice] if p_item[1] <= salary: #判断用户是否能够买得起 shop_car.append(p_item) salary -= p_item[1] print("您已购买了\033[32;1m[%s]\033[0m,您的账户余额为\033[32;1m[%s]\033[0m元"% (p_item,salary)) else: print("您的账户余额不足,如需充值请输入p,选择其它商品请输入j:") t = False while not t: choice = input() if choice == 'p': salary_add = (input("请输入您需要充值的金额:")) if salary_add.isdecimal(): salary += int(salary_add) print ("您好,您的账户余额为:\033[32;1m[%s]\033[0m元,如需充值请输入p,继续购物请输入j:"% salary) else: print ("请输入正确的充值金额!") elif choice == 'j': t = True else: print ("请输入正确的选项!") else: print("商品列表中无该商品!") elif user_choice == 'q': exit("欢迎下次光临!") elif user_choice == 'c': print ("您已购买了\033[32;1m[%s]\033[0m,您的账户余额为\033[32;1m[%s]\033[0m元"% (shop_car,salary)) else: print("请输入正确的序号!")