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 the number to search"))
  13. r=(a,n,0,len(a)-1)
  14. if r!= -1:
  15. print("Element found at index:"+str(r))
  16. else:
  17. print("Element not found ")
  18.  
Success #stdin #stdout 0.03s 9720KB
stdin
3
stdout
Enter the number to searchElement found at index:([1, 2, 3, 4, 5, 6, 7, 8, 9], 3, 0, 8)