-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathCity_distance.py
More file actions
executable file
·58 lines (50 loc) · 1.49 KB
/
Copy pathCity_distance.py
File metadata and controls
executable file
·58 lines (50 loc) · 1.49 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
from math import *
def distance(coord1, coord2):
"""
This uses the formula 'haversine' to calculate the great-circle distance b/w two points - that is the shortest distance over the earth surface.
"""
lat1, long1 = coord1
lat2, long2 = coord2
R = 6371
a = (sin((lat2 - lat1) / 2)) ** 2 + cos(lat1) * cos(lat2) * (
sin((long2 - long1) / 2)
) ** 2
c = 2 * (atan2(a ** 0.5, (1 - a) ** 0.5))
d = R * c
return d
if __name__ == "__main__":
print("\n\nEnter The co-ordinate of two cities : \n")
latitude1, longitude1 = (
float(x) for x in input("Enter Latitude and Longitude : ").split()
)
latitude2, longitude2 = (
float(x) for x in input("Enter Latitude and Longitude : ").split()
)
dist = distance((latitude1, longitude1), (latitude2, longitude2))
print("Choose your unit to display : ")
print("The Distance between two cities : \n")
print(
"1. Kilometers\n2. Meters\n3. Miles\n4. Inches\n5. Foot\n6. Yard\n7. Light Year\n0. Exit"
)
ch = int(input("Enter your choice : "))
if ch == 0:
print("Thank You..!!")
exit()
elif ch == 1:
pass
elif ch == 2:
pass
elif ch == 3:
pass
elif ch == 4:
pass
elif ch == 5:
pass
elif ch == 6:
pass
elif ch == 7:
pass
else:
print("Wrong Choice..!!")
print("Try Again....")
print(dist)