Reputation: 1
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.
I tried but I am taking 2 inputs to get the result I want the hour and minute to be taken in one input and to get the required output
Upvotes: 0
Views: 668
Reputation: 2006
Code:- To find minimum angle(Q)
# Time O(1)
# To find angle :- angle(Q)=(11/2)*minutes-(30*hour)
hour,minutes=map(int,input("Input the time Format [HH:MM]: ").split(":"))
if hour>12: #Converting digital to analog..!
hour-=12
angle=min(abs(((11/2)*minutes)-(30*hour)),360-abs(((11/2)*minutes)-(30*hour)))
print(angle)
Output:-
Input the time Format [HH:MM]: 12:40
140.0
Upvotes: 0
Reputation: 33
the statement "i am taking 2 inputs to get the result i want the hour and minute to be taken in one input" sounds like an implementation problem, and I can't really help with that without looking at your homework code.
for the other problem, think algorithmically; the two hands are essentially independent. the angle (from the vertical) of each is determined by the fraction of their sweep cycle (60 minutes for the big hand, 12 hours for the small hand) times 2 pi radians. The smaller angle will be the absolute value of the difference between the two, i.e. 2 * pi * abs( (big hand/60) - (small hand/12) ).
Good luck!
Upvotes: 1