0.1 + 0.2 == 0.3 is False in Python due to binary floating-point representation. Write a function nearly_equal(a, b, tolerance=1e-9) that returns True if two floats a and b are equal within tolerance, and False otherwise. This is the correct way to compare floats.nearly_equal(0.1 + 0.2, 0.3)
True
The tiny representational error is within tolerance.
nearly_equal(1.0, 1.5)
False
Difference of 0.5 exceeds tolerance.
Compare `abs(a - b)` against tolerance.
Do not use `==` directly on the floats.