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("輸入有誤,請從新輸入!")