programming-examples/python/Misc/Python program to compute and return the square root of a given 'integer'.py
2019-11-15 12:59:38 +01:00

15 lines
355 B
Python

def my_sqrt(x):
if x<2: return x
left=1
right=int(x/2)+1
while left<=right:
mid=int((left+right)/2)
if mid*mid==x:
return mid
if mid*mid>x:
right=mid-1
else:
left=mid+1
return right
print(my_sqrt(16))