Skip to content

Commit 5694180

Browse files
author
Amogh Singhal
authored
Update calculateClockAngle.py
1 parent 6342cab commit 5694180

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

calculateClockAngle.py

+8
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,17 @@ def calculateAngle(hour, minute):
1212
if minute == 60:
1313
minute = 0
1414

15+
# hour hand moves 360° in 12 hours i.e.
16+
# 360/12*60 ==> 0.5° every minute
17+
18+
# similarly minute hand moves 360° in 1 hour i.e.
19+
# 360/60 ==> 6° every minute
20+
1521
hour_angle = (hour * 60 + minute) * 0.5
1622
minute_angle = minute * 6
1723

24+
# We take the absolute difference
25+
# and then return the acute angle between the two
1826
difference = abs(hour_angle - minute_angle)
1927

2028
return min(difference, 360 - difference)

0 commit comments

Comments
 (0)