Created
April 20, 2017 21:58
-
-
Save BlackVikingPro/5b864de704270f7332cb6802a3cf9aa4 to your computer and use it in GitHub Desktop.
Get the square root of a number example in Python!
This file contains hidden or 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
#!/usr/bin/env python | |
""" !- Square Root Example in Python -- By: @BlackVikingPro -! """ | |
import sys | |
# Based on JavaScript code from https://gist.github.com/joelpt/3824024 | |
def squirt(n, g=False): | |
if (g == False): | |
g = n / 2.0; | |
pass | |
d = n / g; | |
ng = (d + g) / 2.0; | |
if (g == ng): | |
return g | |
return squirt(n, ng); | |
pass | |
if __name__ == '__main__': | |
try: | |
print squirt(int(sys.argv[1]), int(sys.argv[2])) | |
pass | |
except IndexError: | |
if (len(sys.argv) == 2): | |
print squirt(int(sys.argv[1]), False) | |
sys.exit() | |
pass | |
print "Please define something to square root." | |
print "Example: ./sqrt.py 81" | |
pass | |
pass |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment