lst0 = ['购买商品','金额'] lst1 = ['1.','iphone6s','5800'] lst2 = ['2.','mac book','9000'] lst3 = ['3.','coffee','32'] lst4 = ['4.','python book','80'] lst5 = ['5.','bicycle','1500'] c = 1 while 1>0: salary = input("Salary = ") if salary.isdigit(): salary = int(salary) break print(lst1[0],lst1[1],lst1[2]) print(lst2[0],lst2[1],lst2[2]) print(lst3[0],lst3[1],lst3[2]) print(lst4[0],lst4[1],lst4[2]) print(lst5[0],lst5[1],lst5[2]) while 1 > 0: a = input('>>>:') if a == 'quit': d = 0 for i in range(c): print(lst0[d], lst0[d + 1], end='\n') d += 2 print('您的余额为:',salary) print('欢迎下次光临') break elif a.isdigit(): a = int(a) if 0 < a < 6: if a == 1: lst = lst1 elif a == 2: lst = lst2 elif a == 3: lst = lst3 elif a == 4: lst = lst4 elif a == 5: lst = lst5 if salary >= int(lst[2]): print(lst[1], '已经加入您的购物车,当前余额:', salary - int(lst[2])) salary = salary - int(lst[2]) lst0.append(lst[1]) lst0.append(lst[2]) c += 1 else: print('余额不足,', salary - int(lst[2]))