#exercise 2.21 from A primer...
a = (1/947.0)*947
b = 1
tol = 1e-10
#Slightly modified version from the book, to demostrate
#comparison of floats with a tolerance
#Checking for equality does not (always) work:
if abs(a-b) == tol:
print('The numbers are exactly equal...')
#Checking with a tolerance works:
if abs(a-b) < tol:
print('The numbers are equal to a tolerance...')
"""
Terminal> python compare_floats.py
The numbers are equal to a tolerance...
"""