Created
November 21, 2017 15:21
-
-
Save talhaHavadar/30e19737c714d8e8411afef0ea9d1cf8 to your computer and use it in GitHub Desktop.
Implementation of Babylon algorithm to find root of the number
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
""" | |
Implementation of Babylon algorithm to find roots of the number | |
@author Talha Can Havadar | |
""" | |
def root(number, degree): | |
""" | |
Takes the root of the given number according to given degree | |
and returns the rooted number as a result | |
""" | |
z = number | |
w = 1 | |
e = 0.000001 | |
while z - w > e: | |
z = ((degree - 1) * z + w) / degree | |
w = number / (z ** (degree - 1)) | |
return z | |
def main(): | |
""" | |
Cause I like main functions | |
""" | |
degree_of_root = int(input("Please enter the degree of the root: ")) | |
number = int(input("Please enter the number which will be rooted: ")) | |
print("Result:", root(number, degree_of_root)) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment