Find latitude and longitude of first 20 countries with a population greater than or equal to the population limit given below. Use the country details from this dataset.
Your task is to find the sum of the length of all lines (in kms) that can be drawn between co-ordinates of these countries.
from math import radians, asin, sqrt, cos, sin
def distance(lt1, lt2, lg1, lg2):
lon1 = radians(lg1)
lg2 = radians(lg2)
lt1 = radians(lt1)
lt2 = radians(lt2)
dist_lon = lg2 - lg1
dist_lat = lt2 - lt1
res = sin(dist_lat / 2)**2 + cos(lt1) * cos(lt2) * sin(dist_lon / 2)**2
ct = 2 * asin(sqrt(res))
radius = 6371
return(ct * radius)
lt1 = eval(input("Enter first latitude: "))
lt2 = eval(input("Enter second latitude: "))
lg1 = eval(input("Enter first longitude: "))
lg2 = eval(input("Enter second longitude: "))
print(distance(lt1, lt2, lg1, lg2), "KM")
Comments
Leave a comment