[Tutor] Python Program: Newton's Method
bgailer at gmail.com
Tue Jan 27 18:06:07 CET 2009
I neglected to mention that we'd like you to always reply-all so a copy
goes to the list. All of us participate and learn.
Donna Ibarra wrote:
> The numbers that are outputted are not exactly correct as they should
> be for Newtons Method:
OK - thanks - now please give us a few sample numbers, the results you
want and the results you get.
> import math
> def main():
> x, loops = input("Please enter the value, and the number of times
> to loop: ")
> for i in range(loops):
> new_loops = float(loops + (x / loops)) / 2
> loops = new_loops
> print "The guess is", loops, "which is", loops -
> math.sqrt(x),"away from", math.sqrt(x)
> ^Do you have any suggestions as to what I should do?
Chapel Hill NC
More information about the Tutor