""" Ex. 2.21 from "A primer on..." Demonstrate why we should always use a tolerance when comparing floats. """ a = 1 / 947.0 * 947 b = 1 if a != b: print('Wrong result!') tol = 1e-14 if abs(a - b) < tol: print('Correct result') """ Terminal> python compare_floats.py Wrong result! Correct result """