1 li = ["手机", "电脑", "鼠标垫", "游艇"] 2 good = {} 3 4 for i in li: 5 goodid = str(li.index(i) + 1) 6 print("{0}\t\t{1}".format(goodid, i)) 7 good[goodid] = i 8 9 while True: 10 userInputId = input("请输入选择的商品序号: ") 11 if userInputId in good: 12 print(userInputId + ' ' + good.get(userInputId)) 13 break 14 elif userInputId == 'Q' or userInputId == 'q': 15 exit() 16 else: 17 print("输入有误,请重新输入!")