The solution below is one approach. Note that we must convert the provided arguments from string values representing angles in degrees to float
s in radians.
import sys
import math
# Calculate the shortest distance between two points on a sphere provided on
# the command line as (longitude, latitude pairs). For example, Paris and Rome:
# 48.9,2.4 41.9,12.5
haversin = lambda alpha: math.sin(alpha/2)**2
def gc_distance(loc1, loc2, R=6378.1):
"""
Return the great-circle distance between two points on a sphere of radius
R, provided as (latitude, longitude) pairs, loc=(phi, lamdbda) in radians.
"""
(phi1, lambda1), (phi2, lambda2) = loc1, loc2
d = 2 * R * math.asin(math.sqrt(haversin(phi2-phi1)
+ math.cos(phi1)*math.cos(phi2)*haversin(lambda2-lambda1)))
return d
loc1, loc2 = sys.argv[1:]
phi1, lambda1 = [math.radians(float(x)) for x in loc1.split(',')]
phi2, lambda2 = [math.radians(float(x)) for x in loc2.split(',')]
d = gc_distance((phi1, lambda1), (phi2, lambda2))
print('{} km'.format(int(d)))