#!/usr/bin/env python from math import * def floorSqrt(A=2): assert(A>=0) x = floor(sqrt(A)) # TODO: compute it without sqrt ! return x def heron(A=2, nmax=7, name="Ex17datas.txt"): u = floorSqrt(A) myfile = open(name, "a") for i in xrange(0,nmax): print("u[%i] = %.20f" % (i,u)) myfile.write("%i %.20g\n" % (i,u)) u = (u + (2./u))/2. if __name__ == '__main__': heron()