#Searching element from list by traversal
from random import*
Flag=1
times_Appear=0while Flag:
list_Length=int(input("Enter the length of list(Length>=25) :"))if list_Length<25:print("Length doesn't meet the requests")
Flag=0else:
List_Before=[1]*list_Length
"""
Initialization list
"""
for index_First inrange(0,list_Length):
List_Before[index_First-1]=randint(1,100)print("A list of length {} generated from random numbers is :".format(list_Length))for index_First inrange(0,list_Length):print(List_Before[index_First],end=' ')
number_Search=int(input("Enter the number you want to search :"))for index_First inrange(0,list_Length):if number_Search==List_Before[index_First]:
times_Appear+=1print("{} in list in location {}".format(number_Search,index_First))if times_Appear==0:print("{} not in the list".format(number_Search))print("{} appear {} times,the possiblity of appearance is {}".format(number_Search,times_Appear,times_Appear/list_Length))
Flag=int(input("\nEnter 1 to cotinue and 0 to exit :"))if Flag!=1 and Flag!=0:
Flag=0print("The Flag you input is not meet the requests,force exit")
Python利用遍历法查找列表中某一特定元素#Searching element from list by traversalfrom random import *Flag=1times_Appear=0while Flag: list_Length=int(input("Enter the length of list(Length>=25) :")) if list_Length<25: print("Length doesn't meet the