Question: I am working on python basics coding. I cant figure out how to convert it back into miles. Here is the problem. The great-circle distance

I am working on python basics coding. I cant figure out how to convert it back into miles.

Here is the problem.

The great-circle distance d between two locations of latitude-longitude pair (x1, y1) and latitude-longitude pair (x2, y2), in degrees, is given by the following equation: d = E arccos(sin(x1) sin(x2) + cos(x1) cos(x2) cos(y1 - y2)) where E, the earth's radius, is 3956 (miles) Important: the trigonometric functions in Python use radians, while the latitude and longitude use degrees, so it is essential to also use functions from the math module which convert between degrees and radians in your program. [evaluate greatCircle.py] Enter the latitude of location 1: 48.8539 Enter the longitude of location 1: 2.2913 Enter the latitude of location 2: 27.1751 Enter the longitude of location 2: 78.0399 The great circle distance between these locations is 4197.2276 miles. In your output statement, please use the exact format as shown above. You should round the output (and any inputs) to four decimal places after the decimal point.

Here is my code.

#R is radius of the earth R = 3956

lat1_string = input("Enter the lattitude of the first location: ") lon1_string = input("Enter the longitude of the first location: ") lat2_string = input("Enter the lattitude of the second location: ") lon2_string = input("Enter the longitude of the second location: ")

lat1 = float(lat1_string) lon1 = float(lon1_string) lat2 = float(lat2_string) lon2 = float(lon2_string)

lat1_radians = math.radians(lat1) lon1_radians = math.radians (lon1) lat2_radians = math.radians (lat2) lon2_radians = math.radians (lon2)

distance = R * acos(sin(lat1) * sin(lat2) + cos(lat1) * cos(lat2) * cos(lon1 - lon2))

print ("The great circle distance between these locations is" distance)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!