Problem 2.1 : Distance (100 pts)
We will now implement the function distance, which computes the distance between two city objects. Recall that the distance between two coordinate pairs (x1, y1)
and (x2, y2)
can be found by calculating the sqrt of (x1 - x2)**2 + (y1 - y2)**2
. We have already imported sqrt
for your convenience. Use the latitude and longitude of a city as its coordinates; you'll need to use the selectors to access this info!
from math import sqrt
def distance(city1, city2):
"""
>>> city1 = make_city('city1', 0, 1)
>>> city2 = make_city('city2', 0, 2)
>>> distance(city1, city2)
1.0
>>> city3 = make_city('city3', 6.5, 12)
>>> city4 = make_city('city4', 2.5, 15)
>>> distance(city3, city4)
5.0
"""
"*** YOUR CODE HERE ***"