Skip to content

Commit f6bfcab

Browse files
author
Amogh Singhal
authored
Create calculateClockAngle.py
1 parent 114cbe8 commit f6bfcab

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

calculateClockAngle.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Find the angle made by the hour hand and the minute
2+
# hand at any given time. Assume it is an analog clock
3+
4+
def calculateAngle(hour, minute):
5+
if hour < 0 or minute < 0 or hour > 12 or minute > 60:
6+
print("Wrong inputs given...")
7+
return
8+
else:
9+
10+
if hour == 12:
11+
hour = 0
12+
if minute == 60:
13+
minute = 0
14+
15+
hour_angle = (hour * 60 + minute) * 0.5
16+
minute_angle = minute * 6
17+
18+
difference = abs(hour_angle - minute_angle)
19+
20+
return min(difference, 360 - difference)
21+
22+
input_time = (9, 30)
23+
print("The angle between hour and minute hand is: ", calculateAngle(input_time[0], input_time[1]), '\u00b0')

0 commit comments

Comments
 (0)