Skip to content

Instantly share code, notes, and snippets.

@viveksyngh
Created August 6, 2015 21:22
Show Gist options
  • Select an option

  • Save viveksyngh/e0872ad3863a265eb4fe to your computer and use it in GitHub Desktop.

Select an option

Save viveksyngh/e0872ad3863a265eb4fe to your computer and use it in GitHub Desktop.
Finds SQRT of an integer
__author__ = 'Vivek'
#Find Square root of an inetger , if Square root is not integer returns floor of sqrt
def sqrt(A) :
if 2 > A :
return A
low = 0
high = A
while high > low + 1 :
num = (low + high)/2
if num**2 < A :
low = num
elif num**2 > A :
high = num
else :
break
if A == num**2:
return num
else :
return low
print(sqrt(25))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment