Answer to Question #275121 in Python for siva

Question #275121

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. 

  • Assume radius of earth: 6371 km
  • Round length of each line and final result to 2 decimal points
  • If co-ordinates are missing for any country use 0.000 N 0.000 E
1
Expert's answer
2021-12-03T14:34:47-0500
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")

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS