-
Notifications
You must be signed in to change notification settings - Fork 0
/
assignment-3.py
35 lines (24 loc) · 1.01 KB
/
assignment-3.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import math
def get_coordinates():
easting = float(input("Enter easting coordinate: "))
northing = float(input("Enter northing coordinate: "))
return easting, northing
def calculate_distance(coord1, coord2):
return math.sqrt((coord1[0] - coord2[0])**2 + (coord1[1] - coord2[1])**2)
def calculate_midpoint(coord1, coord2):
midpoint = ((coord1[0] + coord2[0]) / 2, (coord1[1] + coord2[1]) / 2)
return midpoint
# Code to get coordinates for Town A
print("Enter coordinates for Town A:")
town_a_coords = get_coordinates()
print("")
# Code to get coordinates for Town B
print("Enter coordinates for Town B:")
town_b_coords = get_coordinates()
print("")
# Task (a): Calculate distance between Town A and Town B
distance_ab = calculate_distance(town_a_coords, town_b_coords)
print(f"Distance between Town A and Town B: {distance_ab:.2f} meters")
# Task (b): Calculate midpoint coordinates
midpoint_coords = calculate_midpoint(town_a_coords, town_b_coords)
print(f"Midpoint coordinates: {midpoint_coords}")