from decimal import * # abs(b-h)>=Decimal("0.00000000001") def radq(x): """ algoritmo di Erone per la radice quadrata fallisce per x =0 if x==0: return 0 else: h = x/Decimal(10) b = Decimal(10) dep = b n = 0 while h!=dep: dep = h h = (h+b)/2 b = x/h print h,' ', b, ' ', dep n = n+1 print n return +h """ if x==0: return 0 else: h = x/10 b = 10 dep = b n = 0 while h!=dep: dep = h h = (h+b)/2 b = x/h print h,' ', b, ' ', dep n = n+1 print n return +h