#quote from 'introduction to computation and programming using python, revised edition, MIT'
def squareRootExhaustive(x, epsilon):
"""Assumes x and epsilon are positive floats & epsilon < 1
Returns a y such that y*y is within epsilon of x"""
step = epsilon**2
ans = 0.0
while abs(ans**2 - x) >= epsilon and ans*ans <= x:
ans += step
if ans*ans > x:
raise ValueError
return ans
exhaustive enumeration demo
最新推荐文章于 2023-03-13 22:05:31 发布