Problem 1. (Geo Location) Define a data type Location in location.py that repres
ID: 3713566 • Letter: P
Question
Problem 1. (Geo Location) Define a data type Location in location.py that represents a location on Earth using its latitude and longitude. The data type must support the following API: method Location(lat, lon) 1.distanceTo (m) str (1) description a new location I from the given latitude and longitude values the great-circle distance between l and m the string representation of 1 as (lat, lon) t See Problem 7 from Project 2 for the great-circle distance formula. $ python location.py 48.87-2.33 37.8 -122.4 loc1 (48.87, -2.33) loc2 (37.8, -122.4) d(loc1, loc2)8701.38954 324 Linux Mint [Running] location.py (/coursework/homework9) File Edit View Search Tools Documents Help import math import stdio import sys class Location: Represents a location on Earth def init (self, lat, lon): Constructs a new location given its latitude and longitude values. self. lat-... self._lon - def distanceTo(self, other): Returns the great-circle distance between self and otherExplanation / Answer
class Location: def __init__(self, lat, lon): self._lat = lat self._lon = lon def distanceTo(self, other): return ((self._lat - other._lat)**2 + (self._lon - other._lon)**2) ** 0.5 def __str__(self): return "(" + str(self._lat) + ", " + str(self._lon) + ")"
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.