-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSeunP6.py
More file actions
62 lines (42 loc) · 1.6 KB
/
Copy pathSeunP6.py
File metadata and controls
62 lines (42 loc) · 1.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#SeunP6.py
#Programmer: A. Seun Ajayi
#Purpose: A program that calculates the distance between two geographic points
import math
def main():
#Calls to header function
header()
calContinue = True
#Ends calculation if user enters no
while calContinue:
point1 = tuple(get_location())
point2 = tuple(get_location())
Caldistance = distance(point1, point2)
print(f"The distance between points {point1} and {point2} is {Caldistance:.2f}\n")
#Checks to do another
choice = input("Do you want to do another calculation? (yes/no): ").lower()
if choice == "no":
calContinue = False
print("\nThank you, goodbye!")
#Prints out message
def header():
print("Welcome, the purpose of this program is to calculate the distance between two geographic points.\n")
#Gets location
def get_location():
result = []
lat = float(input("Enter the latitude in decimal degrees: "))
long = float(input("Enter the longitude in decimal degrees: "))
#append values to list
result.append(lat)
result.append(long)
return result
#Calculates distance
def distance(point1, point2):
try:
a = math.sin((point2[0]-point1[0])/2) * math.sin((point2[0]-point1[0])/2) + math.cos(point1[0]) * math.cos(point2[0]) * math.sin((point2[1]-point1[1])/2) * math.sin((point2[1]-point1[1])/2)
c = 2 * math.atan2(math.sqrt(a), math.sqrt(1-a))
d = 6371.0 * c
except:
print("Error return -1.")
return -1
return d
main()