Hey If you are beginner and want to learn a python then you are on right path. Learn basic as well as advanced programming in Python.

Search

Linear searching in Python.

PYHTON PROGRAM




n=int(input ("Enter array size:"))

arr=[]

print("Enter",n,"elements in array one by one:")

for i in range(0,n):

s=int(input())

arr.append(s)

x=int(input("Enter number you want to search:"))

for  i in range(0,n):

if arr[i]==x:

print("You enterd number",x,"is found at position:",i+1)

break

else:

print("You enterd number is not found")






*** Input && Output ***





No comments:

Post a Comment

let me know which type examples you want to comment me.