Skip to content

Instantly share code, notes, and snippets.

@jasongorman
Created October 2, 2019 09:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jasongorman/ea4437248e7ad891e857357295d19213 to your computer and use it in GitHub Desktop.
Save jasongorman/ea4437248e7ad891e857357295d19213 to your computer and use it in GitHub Desktop.
def sqrt(number):
if(number == 0):
return 0;
g = number/2.0;
g2 = g + 1;
while(g != g2):
n = number/ g;
g2 = g;
g = (g + n)/2;
return g;
def factorial(number):
if not isinstance(number, int) or number < 0:
raise Exception("The input must be a positive integer")
if number == 0:
return 0
f = 1
for i in range(1, number+1):
f = f * i
return f
print('The Square root of 25 =', sqrt(25));
print('The factorial of 5 is ', factorial(5))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment