Binary Search in sotred array using python 3.2

Monday, 12 March 2012
#binary search in a sorted array
a=list(map(int,list(input().split())))
a.sort()
low=0
high=len(a)
n=int(input())
print(a)
while high>low:
mid=(low+high)/2
mid=int(mid)
print(low,high,mid)
if a[mid]==n:
print(mid)
break
elif a[mid]>n:
high=mid
else:
low=mid

Copyright @ 2013 code-craft. Designed by Templateism | MyBloggerLab