forked from lechuzalibre/python-scripts
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclockangle.py
More file actions
33 lines (24 loc) · 861 Bytes
/
Copy pathclockangle.py
File metadata and controls
33 lines (24 loc) · 861 Bytes
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
'''Clock Angle Problem
Clock Angle Problem: Given time in hh:mm format in 24-hour notation, calculate the shorter angle between the hour and minute hand in an analog clock.
Input: 5:30
Output: 15°
Input: 21:00
Output: 90°
Input: 12:00
Output: 0° '''
# Path: Clock Angle/clockangle.py
# taking the input from the user
# if the format is not correct then the program will ask for the input again
a = " "
while len(a) != 5 :
a = input("Enter the time in the format hh:mm: ")
if len(a) != 5:
print("Enter the time in the correct format")
# converting the input into hours and minutes
a = a.split(":")
hours = int(a[0])
minutes = int(a[1])
# calculating the angle between the hour and minute hand
angle = abs((hours*30 + minutes*0.5) - (minutes*6))
# printing the angle
print("The angle between the hour and minute hand is: ", angle)