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.

Recommended Answers

All 8 Replies

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?

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.

Use the fractions module

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

Thanks, Ill try it.

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

Yeah that works great. Thanks very much.

Another nice way to work is this

>>> from fractions import Fraction
>>> second = Fraction(1,1) # [SI unit](http://en.wikipedia.org/wiki/International_System_of_Units)
>>> minute = 60 * second
>>> hour = 60 * minute
>>> day = 23 * hour + 56 * minute
>>> week = 7 * day
>>> week / minute # this is the number of minutes per week !
Fraction(10052, 1)
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.