Hi all
I have been asked to calculate days in a week. I know there is not 24 hours but 23 hours 56 minutes in a siderial day. How do I express that fraction in interactive mode. For example:

print 60*23/56/60*7

or something to that effect. Anyone?
Glenn.

If you want to do integer math only, multiply first. I do not understand what you are meaning with the formula of yours (60s cancel) You want to do fraction of day from the difference in day lengths?

Edited 4 Years Ago by pyTony

I'm not sure what you're asking. If you mean how many sidereal days in 7 24-hour days:

>>> 7.0*24/(23+56.0/60)
7.0194986072423395

Thanks for the replies.
Ok, first an explaination. The earth rotates on its axis once every 24 hours, a day. But the thing is, its not 24 hours, its 23 hours and 56 minutes, to be more precise. Those four minutes that get rounded out each day add up and thats why we have a leap year (an extra day in February) every four years to acoount for those four minutes a day that are rounded out.

So, you ask?

If I want to find the number of minutes in a week, I need to times:

number of minutes in an hour * number of hours in a day * number of days in a week.
Now if I use 24 hours, it would be 60247 = 10080 minutes.

But there isn't 10080 minutes in a week, there is 10052, 28 minutes less than above.

So what I need to do, in interactive mode, is perform a calculation that has the fraction for 23 hours and 56 minutes in in, like (23/56/60).

So my calculation for minutes in a week would be something like:

60*(23/56/60)*7

What I am asking is how do I express that fraction in interactive mode?

Hope that helps.
Glenn.

Edited 4 Years Ago by Bluescreendeath: changed text to code to make explaination simpler

Use the fractions module

>>> from fractions import Fraction
>>> day = 23  + Fraction(56, 60)
>>> day
Fraction(359, 15)
>>> 60 * day * 7
Fraction(10052, 1)

My post above was copied and pasted from the interactive command, you can import modules in the python shell. Otherwise you can write

>>> 60 * (23 + 56.0/60) * 7
10052.0

Edited 4 Years Ago by Gribouillis

This article has been dead for over six months. Start a new discussion instead.