需求:python
salary = int(input("Input your salary: ")) goods = ['iphone', 'book', 'desk', 'cup'] price = [5800, 20, 55, 35] for i in range(4): print(i+1, '--', goods[i], '--', price[i]) cost = 0 cart = [] while True: buy = input("Which would you want? ") if buy.isdigit(): buyid = int(buy) if buyid >= 1 and buyid <= 4: cost += price[buyid-1] if cost > salary: print("No stufficient funds. Try again.") cost -= price[buyid-1] continue cart.append(goods[buyid-1]) print(" Your cost is ", cost, ", Your balance is ", salary-cost) else: print("Input between 1 and 4.") continue elif buy == 'q': for i in cart: print(i, ) print(" Your cost is ", cost, ", Your balance is ", salary-cost) break else: print("Input between 1 and 4, or q(quit).") continue