fork download
  1. def xyz(a,n,L,h):
  2. while L<=h:
  3. mid=L+(h-L)//2
  4. if a[mid]==n:
  5. return mid
  6. elif a[mid]<n:
  7. L=mid+1
  8. else:
  9. h=mid-1
  10. return-1
  11. a=[1,2,3,4,5,6,7,8,9]
  12. n=int(input("Enter a number to search:"))
  13. r=xyz(a,n,0,len(a)-1)
  14. if r!=-1:
  15. print("Element is present at index"+str(r))
  16. else:
  17. print("Not found")
Success #stdin #stdout 0.04s 9788KB
stdin
Standard input is empty
stdout
Enter a number to search:Not found