N = 1 # defines the function for which we want to find the roots #WArning: inputs a, b must have decimal points, else output will be an integer; def NewtonRaph(a,g,dg,N): i=1 while i < N: x1 =a -g(a)/dg(a) i += 1 a=x1 return a,g(a) # defining function g whose zero we want to find; # here, setting it up to find root 2. def g(x): return x**2 -2 def dg(x): return 2*x print NewtonRaph(1.0,g,dg,4)