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 

epsilon 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.

Highlight your code and press Code on the bar above to preserve your indentations.

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.