Calculate the Shortest Distance Between Two Points

Published by zachiah in

Create a function that takes a string of four numbers. These numbers represent two separate points on a graph known as the x-axis (horizontal axis) and y-axis (vertical axis).

The order of coordinates in the string corresponds as follows:

"x1,y1,x2,y2"

Calculate the distance between x and y.

Examples

shortest_distance("1,1,2,1") ➞ 1

shortest_distance("1,1,3,1") ➞ 2

shortest_distance("-5,1,3,1") ➞ 8

shortest_dtance("-5,2,3,1") ➞ 8.06

Notes

All floats fixed to two decimal places (e.g. 2.34).

Watch a quick demo on how Edabit works.