#-*- coding:UTF-8 -*- #環境:python3 print("Enter the numbers between 1 and 100:") enterList=[] #記錄輸入的元素 while 1: a = int(input(">>>")) #將輸入轉換爲int型 if a == 0: print ("Your input:",enterList) break #結束輸入 if a<1 or a>100: #限制只容許輸入1到100之間的數 print("Error!Please enter the numbers between 1 and 100!") else: enterList.append(a) listVisited=[] #保存列表中已經處理過的元素值,避免相同的值處理屢次 for a in enterList: if a in listVisited: #已經處理過a,跳過這次循環 break if enterList.count(a)>1: print("The number",a,"occurs",enterList.count(a),"times!") if enterList.count(a)==1: print"The number", a, "occurs",enterList.count(a), "time!" listVisited.append(a) #處理完a,把a 保存到這個列表中,以便下次跳過a的值