Closest Point to Home

Python for AIMedium+10 XP+10

Closest Point to Home

A delivery drone lives at the point (0, 0). It wants the drop-off spot closest to home.

Part 1: Point(x, y)

Each point stores x, y, and distance: how far it is from (0, 0), worked out as (x ** 2 + y ** 2) ** 0.5, rounded to 2 decimal places.

Part 2: closest_point(coords)

coords is a list of (x, y) pairs. It always has at least one pair. Make a Point for each pair, then return [x, y] of the point with the smallest distance. If two points tie, return the one that comes first.

Examples

Point(6, 8).distance
returns 10.0
coords = [(6, 8), (2, 0)]
returns [2, 0]
coords = [(3, 4), (1, 1), (5, 0)]
returns [1, 1]
Point(3, 4).distance
returns 5.0

Hints

Solve it to unlock the solution

Once your code passes every test, a reference solution shows up here so you can compare it with yours.

solution.py
CtrlEnterto run