-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdistance.py
More file actions
22 lines (18 loc) · 807 Bytes
/
distance.py
File metadata and controls
22 lines (18 loc) · 807 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# Calculates the distance between the two cartesian coordinates
# (x_start,y_start) and (x_fin,y_fin)
# Please note code works with Python ver 3.x
from ucb import main
from math import sqrt
def square (num):
return num * num
def distance (x_start, y_start, x_fin, y_fin):
""" Calculates the distance between the two cartesian coordinates
(x_start,y_start) and (x_fin,y_fin) """
return sqrt(square(x_fin - x_start) + square(y_fin - y_start))
@main
def main():
x_start = float(input("Enter the starting x co-ordinate : "))
y_start = float(input("Enter the starting y co-ordinate : "))
x_fin = float(input("Enter the ending x co-ordinate : "))
y_fin = float(input("Enter the ending y co-ordinate : "))
print ("Distance is ",distance(x_start, y_start, x_fin, y_fin))