Code Challenge
Check whether an approximate decimal sum is close to the intended value, then calculate a three-four-five distance.
Understand the idea
Write your own solution before opening the worked answer. Predict the output from the supplied values, then compare the actual result. Check both an ordinary case and the boundary described below; a passing example is more useful when you can explain why it passes.
Where to try it
Open this example with Try in playground. The code loads as editable text and does not run until you select Run. The first run downloads Python. Each run starts fresh; temporary files created by a script are not files on your PC.
Your task
Check whether an approximate decimal sum is close to the intended value, then calculate a three-four-five distance.
Show the worked solution
import math
print(math.isclose(0.1 + 0.2, 0.3))
print(math.hypot(3, 4))
Check the result
The results are True and 5.0.
Test one more case
Set explicit tolerances and test one value that should pass and one that should fail.