Created
October 2, 2019 10:17
-
-
Save jasongorman/75c3485a71c5928760be72fe9f5923c1 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
def floor(number): | |
return number - (number % 1) | |
def ceiling(number): | |
remainder = number % 1 | |
if remainder == 0: | |
return number | |
return number - remainder + 1 | |
print('The Square root of 25 =', sqrt(25)); | |
print('The factorial of 5 is ', factorial(5)) | |
<<<<<<< HEAD | |
print('The floor of 4.7 is', floor(4.7)) | |
======= | |
print('The ceiling of 1.3 is', ceiling(1.3)) | |
>>>>>>> 421547e63c0edf183b935d41e971dc0a416c835b |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment