Computer Science, asked by XxTheQuestionerxX, 2 months ago

What Is Output Of Following Python C.ode?
def lsearch(ar,item):
i=0
while i<len(ar)and ar[i]!=item:
i+=1
if i<len(ar):
return i
else:
return false
n=int(input("enter desired linear-list size(max.50)..."))
print("\nEnter elements for linear list\n")
ar=[0]*n
for i in range(n):
ar[i]=int(input("element"+str(i)+":"))
item=int(input("\nEnter element to be searched for ..."))
index=lsearch(ar,item)
if index:
print("\nElement found at index:",index,",position:",(index+1))
else:
print("\nsorry!! given element could not be found.\n")

Answers

Answered by Anonymous
2

Answer:

After Running Above Python C.ode The Output

produced is Given in The Above Attachment.

Python Version is Python IDLE 3.8.6 shell

The Answer is an Original answer by Me.

after Interpreting C.odes .

May help future python aspirant

Attachments:
Answered by Anonymous
0

Answer:

def lsearch(ar,item):

i=0

   while i<len(ar)and ar[i]!=item:

i+=1

   if i<len(ar):

       return i

   else:

       return false

n=int(input("enter desired linear-list size(max.50)..."))

print("\nEnter elements for linear list\n")

ar=[0]*n

for i in range(n):

ar[i]=int(input("element"+str(i)+":"))

item=int(input("\nEnter element to be searched for ..."))

index=lsearch(ar,item)

if index:

print("\nElement found at index:",index,",position:",(index+1))

else:

print("\nsorry!! given element could not be found.\n")

Explanation:

Similar questions