Skip to content

Commit 0a32153

Browse files
Geographic Distance: add validate_coordinates() helper and use it in main()
1 parent 026b56e commit 0a32153

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

Geographic Distance/geographic_distance.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,18 @@ def calculate_distance_and_time(coord1, coord2, avg_speed):
1717

1818
return distance, travel_time
1919

20+
def validate_coordinates(coord):
21+
"""Ensure latitude and longitude are within valid ranges."""
22+
lat, lon = coord
23+
if not (-90 <= lat <= 90):
24+
raise ValueError(f"Latitude {lat} out of range (-90..90)")
25+
if not (-180 <= lon <= 180):
26+
raise ValueError(f"Longitude {lon} out of range (-180..180)")
27+
return coord
28+
29+
30+
31+
2032

2133
def main():
2234
# Coordinates (latitude, longitude)

0 commit comments

Comments
 (0)