0

Is it a proper linear search algorithm code? And how can i improve this code?

#LINEAR SEARCH IN PYTHON #FUNCTION DEFINITION def ls(list,value): ind=0 for i in list: if i==value: return int(ind) else: ind=ind+1 return None #INPUT FROM USER n=int(input("Enter no of elements to be added to list :")) list1=[] for i in range(0,n): list1.append(int(input("Enter a no:"))) a=int(input("Enter no to be searched:")) #FUNCTION CALL l=ls(list1,a) if l !=None: print("Number found and is at position",l,"in the list") else: print("Not found")

8th Mar 2019, 11:45 AM
Mohd Adnan
Mohd Adnan - avatar
1 Antwort
8th Mar 2019, 12:35 PM
Diego
Diego - avatar