li = [["1.iphone X",7399],["2.vivo X21",3598],["3.利用Python进行数据分析",72],["4.迪士尼滑板车", 179],["5.索尼无线蓝牙耳机", 1999]]shopping_car = [] #已经购买的列表salarytem = input("请输入你带多少钱来购物:")if not salarytem.isdigit(): exit()salary = int(salarytem)yuer = salary #余额for i in li: print(i)buyindex = ""while True: buy = input("输入'q'退出,请输入购买物品的编号:") if buy.isdigit(): buyindex = int(buy) if buyindex < 1 or buyindex > len(li): print("没有您想要的商品,请重新选择...") continue elif buy == "q": if len(shopping_car) < 1: print("你没有购买任何物品") exit() print("----------------购物车的清单-------------------") for j in shopping_car: print(j) print("你已经购买了以上的商品。剩余金额为:%f元" % yuer) exit() price = li[buyindex-1][1] if (price > yuer): print("\033您的余额不够,剩余:%f\033,请选择其他商品..." % yuer) elif (price <= yuer): yuer = yuer - price shopping_car.append(li[buyindex-1]) print("购买成功,购买商品为:\n" + li[buyindex-1][0])