/
clock_angle_calculator.py
44 lines (38 loc) · 1.11 KB
/
clock_angle_calculator.py
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
def angle_calculation(hour, minute):
try:
hour = int(hour)
if hour in range(0, 24):
if hour in range(0, 12):
pass
else:
hour -= 12
else:
print "Wrong format of hour"
exit(1)
except TypeError:
print "Wrong format of hour"
exit(1)
try:
minute = int(minute)
if minute in range(0, 60):
pass
else:
print "Wrong format of minute"
exit(1)
except TypeError:
print "Wrong format of minute"
exit(1)
hour_degrees = 30
hour_coefficient = 0.5
minute_coefficient = 6
hour_angle = hour * hour_degrees + minute * hour_coefficient
minute_angle = minute * minute_coefficient
return abs(hour_angle - minute_angle)
def main():
try:
hour, minute = raw_input("Please enter time (eq. 15:15): ").split(":")
print "Angle between hour and minute hand is " + str(angle_calculation(hour, minute)) + " degrees."
except ValueError:
print "Wrong time format"
if __name__ == "__main__":
main()