Skip to content

Instantly share code, notes, and snippets.

View LemonPi's full-sized avatar

Johnson Zhong LemonPi

View GitHub Profile
@LemonPi
LemonPi / roots.py
Created October 12, 2013 01:10
Newton's method for finding nth root of number r to p decimal places correct
def newton(n, r, p = 0):
"""
(int(n), num(r), int(p)) -> float
Return the nth root of a positive number r displaying p correct decimals.
"""
x = 1 # start with guess = 1
while True:
fx = x**n - r # function of this form solves all roots