Skip to content

Instantly share code, notes, and snippets.

@talhaHavadar
Created November 21, 2017 15:21
Show Gist options
  • Save talhaHavadar/30e19737c714d8e8411afef0ea9d1cf8 to your computer and use it in GitHub Desktop.
Save talhaHavadar/30e19737c714d8e8411afef0ea9d1cf8 to your computer and use it in GitHub Desktop.
Implementation of Babylon algorithm to find root of the number
"""
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