fork download
  1. goal = 10
  2. root = goal
  3. count = 0
  4.  
  5. while abs(root*root-goal)>= 0.00000000000001:
  6. count+=1
  7. root = 0.5*(root+(goal/root))
  8. print(str(root))
  9.  
  10. print("done in "+str(count)+" iterations")
  11.  
Success #stdin #stdout 0.02s 9984KB
stdin
Standard input is empty
stdout
5.5
3.659090909090909
3.196005081874647
3.16245562280389
3.162277665175675
3.162277660168379
done in 6 iterations