← Back to challenges

Distance Between Two Points

PythonHardmathalgebralanguage_fundamentalsgeometryobjects

Instructions

In this challenge, you have to find the distance between two points placed on a Cartesian plane. Knowing the coordinates of both the points, you have to apply the Pythagorean theorem to find the distance between them.

Two points on a Cartesian plane

Given two dictionaries a and b being the two points coordinates (x and y), implement a function that returns the distance between the points, rounded to the nearest thousandth.

Examples

get_distance({"x": -2, "y": 1}, {"x": 4, "y": 3}) ➞ 6.325

get_distance({"x": 0, "y": 0}, {"x": 1, "y": 1}) ➞ 1.414

get_distance({"x": 10, "y": -5}, {"x": 8, "y": 16}) ➞ 21.095

Notes

  • The "distance" is the shortest distance between the two points, or the straight line generated from a to b.
python3
Loading editor…
to run
Walks through the solution with reasoning and edge cases.
Next: CMS Selector Based on a Given String