1 money = int(input("How much do you have:")) 2 price = [5800, 9000, 32, 80, 1500] 3 goods = ["mobile_phone", "mac_book", "coffee", "python_book", "bicycle"] 4 list_of_goods = ''' 5 ***************商品列表************** 6 序号 商品名 价格 7 1. %-12s %-6d 8 2. %-12s %-6d 9 3. %-12s %-6d 10 4. %-12s %-6d 11 5. %-12s %-6d 12 '''%(goods[0], price[0], goods[1], price[1], goods[2], price[2], goods[3], price[3], goods[4], price[4]) 13 print(list_of_goods) 14 shopping_trolley = list() 15 while True: 16 select = input("do you want to buy>>>:") 17 if select.isdigit(): 18 select = int(select) 19 if select == 1 or select == 2 or select == 3 or select == 4 or select == 5: 20 total = price[select - 1] 21 if total < money: 22 shopping_trolley.append(goods[select - 1]) 23 shopping_trolley.append(price[select - 1]) 24 print("已加入", goods[select - 1], "到你的购物车,当前余额:", money - total) 25 money = money - price[select - 1] 26 else: 27 print("余额不足", money - total) 28 else: 29 print("没有该商品编号") 30 elif select == "quit": 31 print("**********您已购买已下商品**********") 32 for i in shopping_trolley: 33 print(i) 34 print("欢迎下次光临") 35 break 36 else: 37 print("请输入正确的商品编号格式")
浙公网安备 33010602011771号