标签:div col nbsp color pen 购物 NPU 模拟 else
1 goods = [{"name": "电脑", "price": 1999}, 2 {"name": "鼠标", "price": 10}, 3 {"name": "游艇", "price": 20}, 4 {"name": "美女", "price": 998}] 5 lst = [[‘电脑‘, 1999], [‘鼠标‘, 10], [‘游艇‘, 20], [‘美女‘, 998]] 6 lst1 = [0,0,0,0] 7 for i in range(len(goods)): 8 print("{2},,{0},,{1}".format(goods[i]["name"], goods[i]["price"], i + 1)) 9 10 def buy(): 11 global msg1 12 while 1: 13 msg2 = input("请选择你要购买的商品序号:") 14 15 if msg2.isdigit() and 0 < int(msg2) < len(goods) + 1: 16 #lst.append([goods[int(msg2) - 1]["name"], goods[int(msg2) - 1]["price"]]) 17 lst1[int(msg2) - 1] +=1 18 if msg1 > 0: 19 msg1 -= goods[int(msg2) - 1]["price"] 20 else: 21 print("您的购物车余额不足!!") 22 continue 23 24 elif msg2.upper() == "Q": 25 #print("{0},,{1}".format(goods[int(msg)-1]["name"],goods[int(msg)-1]["price"])) 26 j = 0 27 for i in lst1: 28 29 print("您的购物车中有{0},{1}个!".format(lst[j],i)) 30 j += 1 31 print("您的购物车余额为:{}".format(msg1)) 32 break 33 else: 34 print("你的输入有误!!") 35 36 37 def look(): 38 while 1: 39 msg = input("请输入想要查看的商品序号输入Q去购买:") 40 if msg.isdigit() and 0 < int(msg) < len(goods) + 1: 41 print("{0},,{1}".format(goods[int(msg) - 1]["name"], goods[int(msg) - 1]["price"])) 42 elif msg.upper() == "Q": 43 44 buy() 45 break 46 else: 47 print("您输入有误,,请重新输入!!") 48 49 50 while 1: 51 global msg1 52 msg1 = input("请先定义您的钱包余额!!") 53 if msg1.isdigit(): 54 msg1 = int(msg1) 55 56 look() 57 break 58 else: 59 print("请重新输入!")
标签:div col nbsp color pen 购物 NPU 模拟 else
原文地址:https://www.cnblogs.com/NoteBook3013/p/10222960.html