它没有用......没找到就是一切的答案

时间:2017-07-20 15:26:06

标签: python-3.x

num_array = list( )
num =int(input("Enter how many elements you want:"))
print ('Enter numbers in array: ')
for i in range(int(num)):
    n = input("num :")
    num_array.append(int(n))
print ('LIST: ',num_array)
key=int(input ('enter element to be searched:'))
if key==num_array[i]:
    print('element found')
else:
    print("not found")

所有关于python中的简单线性搜索我使用了C的伪代码并实现了它 enter image description here

1 个答案:

答案 0 :(得分:0)

基本上,你只是忘了在检查时循环遍历循环。

key=int(input ('enter element to be searched:'))
found = False;
for num in num_array:
    if key==num:
        print('element found')
        found = True;
if(found==False)
    print("not found")