Having a hard time trying to calculate the size of the degree of the hour hand in an analogue clock, python

I am having a hard time trying to calculate the size of the degree between the hour hand and midnight in an analogue clock, python. Again, this is part of the Snakify Python problem solving challenges and, I have solved various questions since my last correspondence but, quite reasonably, this is marked as "Very Hard". So, this is my code... Could somebody tell me what I am doing wrong? Thank God no float numbers are included in this question, but this time the problem is probably algorithmic... So:

H = int(input())
M = int(input())
S = int(input())

hours = H * 3600
minutes = M * 60
seconds = S
time = hours + minutes + seconds
calc = time / 86400
deg = calc * 3.6
print(deg)

Much appreciated.

Upvotes: 0

Views: 1146

Answers (3)

SK Sarfaraz ALI
SK Sarfaraz ALI

Reputation: 21

a = float(input())
mintue_deg=float (((a*60/30)*(90/15))%360)
print(mintue_deg)

Upvotes: 0

Thierry Lathuille
Thierry Lathuille

Reputation: 24280

You have correctly calculated your time in seconds.
Let's convert it to hours first:

time_in_hours = time / 3600

The result is a float, but you really don't need to worry about that.

time_in_hours can be less or greater than 12 (and while time keeps flying, it can be greater than 24, 36 or whatever....)
As our clock displays 12 hours, we are only interested in the remainder after we removed as many complete 12-hours periods from our time as possible. This is the remainder of the division by 12, which you calculate with the modulo operator, %:

remainder = time_in_hours % 12

We can now convert this in degrees. We know that 12 hours corresponds to 360 degrees, so it's 360/12 = 30 degrees for each hour.

So you angle is simply:

angle = remainder * 30

Upvotes: 1

Błotosmętek
Błotosmętek

Reputation: 12927

Where does 3.6 come from? That should be 360 (degrees to the whole circle). Besides, if your analog clock is 12-hours but your input uses 24-hours system, you should use H % 12 instead of just H.

Upvotes: 0

Related Questions