from fractions import * def Heron2(a,x,n): x= Fraction(x) for i in range(n): x=(x+3/x)/2 return x