What Is Output Of Following Python C.ode?
defbinsearch(ar,key):
low=0
high=len(ar)-1
while low<=high:
mid=int((low+high)/2)
if key==ar[mid]:
return mid
elif key<ar[mid]:
high=mid-1
else:
low=mid+1
else:
return-999
ar=[12,15,21,25,28,32,33,36,43,45]
item=int(input("enter search item:"))
res=binsearch(ar,item)
if res>=0:
print(item,"FOUND at index",res)
else:
print("sorry!",item,"NOT FOUND in array
Answers
Answered by
0
Answer:
defbinsearch(ar,key):
low=0
high=len(ar)-1
while low<=high:
mid=int((low+high)/2)
if key==ar[mid]:
return mid
elif key<ar[mid]:
high=mid-1
else:
low=mid+1
else:
return-999
ar=[12,15,21,25,28,32,33,36,43,45]
item=int(input("enter search item:"))
res=binsearch(ar,item)
if res>=0:
print(item,"FOUND at index",res)
else:
print("sorry!",item,"NOT FOUND in array
Answered by
1
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 .
Attachments:
Similar questions