x = 25
epsilon = 0.01
numGuesses = 0
ans = 0.0
while abs(ans**2 - x) >= epsilon and ans <= x:
ans += 0.00001
numGuesses += 1
print 'numGuesses =', numGuesses
if abs(ans**2 - x) >= epsilon:
print 'Failed on square root of', x
else:
print ans, 'is close to square root of', x
MustafaScript
0
Newbie Poster
Recommended Answers
Jump to Postepsilon has no special meaning in python. It is a valid identifier which can be used as a variable name as in the above code. In numerical analysis, epsilon is typically used to denote a positive quantity close to zero.
All 2 Replies
Gribouillis
1,391
Programming Explorer
Team Colleague
vegaseat
1,735
DaniWeb's Hypocrite
Team Colleague
Be a part of the DaniWeb community
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.