-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSeunP9.py
More file actions
53 lines (44 loc) · 1.58 KB
/
Copy pathSeunP9.py
File metadata and controls
53 lines (44 loc) · 1.58 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
#SeunP9.py
#Programmer: A. Seun Ajayi
#Email: aajayi@cnm.edu
#Purpose: create a better class
import math
import GeoPoint
def main():
#Constructor to set point
point1 = GeoPoint.GeoPoint(36.16,-86.77,"Nashville")
point2 = GeoPoint.GeoPoint()
point2.Pcoordinate = 35.07,-106.64
point2.descP = "Albuquerque"
calContinue = True
#Gets input and calls class method to calculate distance
while calContinue:
#Trys to get input values
try:
userLat = float(input("Enter you Latitude: "))
userLon = float(input("Enter you Longitude: "))
userDesc = input("Enter the Description: ")
#catches the errors
except TypeError:
print("Wrong type of input!")
except Exception as e:
print ("Something went wrong:", e)
#If no error execute code
else:
pointUser = GeoPoint.GeoPoint(userLat, userLon,userDesc)
distanceToOne = point1.Distance(pointUser)
distanceToTwo = point2.Distance(pointUser)
#logical test, which distance is closer
if distanceToOne < distanceToTwo:
print(point1)
else:
print(point2)
#Runs code regardless of error or not
finally:
#Checks to do another
choice = input("Do you want to do another calculation? (y/n): ").lower()
if choice == "n":
calContinue = False
print("\nThank you, goodbye!")
if __name__ == "__main__":
main()