# -*- coding: utf-8 -*- def heron1(x, n): res = float(x) for i in range(n): res = (res + x / res) / 2 return res def heron2(x, n): if n == 0: return x else: return (heron2(x, n - 1) + float(x)/heron2(x, n - 1)) / 2 def heron3(x, n): if n == 0: return x else: # Un seul appel récursif ... xn1 = heron3(x, n - 1) # ... même si on utilise deux fois la valeur return (xn1 + float(x)/xn1) / 2 print(heron1(2, 23)) print(heron2(2, 23)) print(heron3(2, 23))