-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDDtoDMS
More file actions
65 lines (54 loc) · 1.96 KB
/
DDtoDMS
File metadata and controls
65 lines (54 loc) · 1.96 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
"""
This Code Converts DD to DMS
___author___ = Meghan Kulkarni <msk160530@utdallas.edu>
"""
import math
ch = 'Y'
while ch == 'Y' or ch == 'y':
flag = 0
while flag == 0:
try:
x = float(input("Enter Degree Latitude:"))
y = float(input("Enter Degree Longitude:"))
y_o = 0
x_o = 0
if math.trunc(x) in range(-90, 90) \
and math.trunc(y) in range(-180, 180):
if math.trunc(x) < 0:
x_o = x
x *= -1
degree = math.trunc(x)
minute = math.trunc((x * 60) % 60)
seconds = (math.fabs(x) * 3600) % 60
if x_o < 0:
print("-" + str(degree) + "\u00b0" + str(minute) + "'" +
"{:.4f}".format(seconds) + "\"" + " S")
else:
print(str(degree) + "\u00b0" + str(minute) + "'" +
"{:.4f}".format(seconds) + "\"" + " N")
if math.trunc(y) < 0:
y_o = y
y *= -1
degree = math.trunc(y)
minute = math.trunc((y * 60) % 60)
seconds = (math.fabs(y) * 3600) % 60
if y_o < 0:
print("-" + str(degree) + "\u00b0" +
str(minute) + "'" + "{:.4f}".format(seconds) +
"\"" + " W")
else:
print(str(degree) + "\u00b0" +
str(minute) + "'" + "{:.4f}".format(seconds) +
"\"" + " E")
flag = 1
break
else:
print("Invalid Range")
except ValueError:
print("Invalid Characters in Input....!")
ch = input("Want to do Another Conversion(Y/N)?")
if ch == 'y' or ch == 'Y':
continue
else:
print("Press Enter to Continue.....")
break