-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSeunP10.py
More file actions
69 lines (54 loc) · 2.07 KB
/
Copy pathSeunP10.py
File metadata and controls
69 lines (54 loc) · 2.07 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
63
64
65
66
67
68
69
#SeunP10.py
#Programmer: A. Seun Ajayi
#Email: aajayi@cnm.edu
#Purpose: get point from a file
import GeoPoint
def main():
pointList = []
pointResult = []
resultPoint = GeoPoint.GeoPoint()
#reads from csv file
with open("pointfile.csv") as file:
for line in file:
lat,lon,desc = line.rstrip().split(",")
newPoint = GeoPoint.GeoPoint(float(lat),float(lon),desc)
#assigns point to point list
pointList.append(newPoint)
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)
location = 0
#iterate each point and set value to closest
for dPoint in pointList:
pointResult.append(dPoint.Distance(pointUser))
#assigns the first element as minimum
minPoint = pointResult[0]
#If element is min set to value and index
for i in range(len(pointResult)):
if pointResult[i] < minPoint:
minPoint = pointResult[i]
location = i
#remove all elements in sequence
pointResult.clear()
print(pointList[location])
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()