What is the output of this code that calculates the distance between two GPS coordinates using the Haversine formula?
import math def haversine(lat1, lon1, lat2, lon2): R = 6371 # Earth radius in km phi1 = math.radians(lat1) phi2 = math.radians(lat2) dphi = math.radians(lat2 - lat1) dlambda = math.radians(lon2 - lon1) a = math.sin(dphi/2)**2 + math.cos(phi1)*math.cos(phi2)*math.sin(dlambda/2)**2 c = 2 * math.atan2(math.sqrt(a), math.sqrt(1 - a)) return R * c print(round(haversine(52.2296756, 21.0122287, 41.8919300, 12.5113300), 2))
Remember the Haversine formula calculates great-circle distance between two points on a sphere.
The code uses the Haversine formula correctly and calculates the distance between Warsaw (52.2296756, 21.0122287) and Rome (41.8919300, 12.5113300) as approximately 1317.53 km.
Which option correctly converts GPS coordinates from degrees, minutes, seconds (DMS) to decimal degrees?
Think about how many minutes are in a degree and how many seconds are in a minute.
To convert DMS to decimal degrees, minutes are divided by 60 and seconds by 3600, then added to degrees.
What error does this code raise when parsing GPS coordinates from a string?
gps_str = "48°51'29.6\"N, 2°17'40.2\"E"
lat, lon = gps_str.split(",")
lat_deg, lat_min, lat_sec = map(float, lat[:-1].split("°"))
lon_deg, lon_min, lon_sec = map(float, lon[:-1].split("°"))
Check how the string is split and converted to float.
The code tries to convert strings like "51'29.6\"N" directly to float, which fails because of non-numeric characters like ' and ".
Which option contains the correct syntax to filter GPS points with latitude greater than 40 using a dictionary comprehension?
gps_points = {"p1": (39.9, -75.2), "p2": (41.1, -74.9), "p3": (40.5, -73.9)}Remember the correct order of clauses in a dictionary comprehension.
Option D correctly uses 'if' after the 'for' clause. Other options have syntax errors or wrong operators.
Given a list of GPS points with timestamps, which option correctly calculates the average speed in km/h between the first and last points?
points = [
{"lat": 52.0, "lon": 21.0, "time": 0},
{"lat": 52.1, "lon": 21.1, "time": 1800}, # 30 minutes later
{"lat": 52.2, "lon": 21.2, "time": 3600} # 60 minutes later
]Use the Haversine formula for distance and convert time difference to hours correctly.
Option A correctly calculates the great-circle distance and divides by elapsed time in hours. Option A uses Euclidean distance which is inaccurate for GPS. Option A divides time by 60 (minutes) instead of 3600 (seconds to hours). Option A uses raw seconds as hours.