From 8cff4beda33d774145dff714d6a449b334d7becd Mon Sep 17 00:00:00 2001 From: Basil Victor Date: Sun, 18 Oct 2020 23:41:19 +0530 Subject: [PATCH] Added program to find distance between two coordinates --- maths/distance.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 maths/distance.py diff --git a/maths/distance.py b/maths/distance.py new file mode 100644 index 000000000000..ac92e5d49c96 --- /dev/null +++ b/maths/distance.py @@ -0,0 +1,16 @@ +""" +Finding distance between a pair of coordinates (x1, y1) and (x2, y2) +""" + + +def getDistance(x1, y1, x2, y2): + """ + Using the standard distance Formula + **2 is to perform square operation + **5 is to perform square root operation + """ + return ((x2 - x1) ** 2 + (y2 - y1) ** 2) ** 0.5 + + +if __name__ == "__main__": + print(f"The distance between the points is {getDistance(2, 4, 7, 16)} units")