[Tutor] class function problem
hugo.yoshi at gmail.com
Wed Sep 22 17:44:17 CEST 2010
On Wed, Sep 22, 2010 at 5:17 PM, Roelof Wobben <rwobben at hotmail.com> wrote:
>> That's very clever. But you might argue that recursion is technically
>> still a loop, albeit an implicit one. There is a simpler way to do
>> this, without loops entirely.
>> Hint: repeated subtraction while your number is greater than some
>> constant, what you are doing, is essentially the same as doing one
>> division operation.
> Sorry. I don't get it.
> When I have 62 seconds that's 1 minutes and 2 seconds.
> I have no clue how I can this with a division.
okay, let's take as an example 314 seconds. We need to convert that
into minutes and seconds:
>>> seconds = 314
>>> seconds / 60.0
See what I did there? This means I can fit 5.2 minutes in 314
seconds.No loops or anything. I'm only interested in the whole
minutes, so I can use the "//" operator for integer division:
>>> seconds // 60
That's our minutes. Now all you need to do is find the number of
seconds left over. The remainder (that's another hint). See if you can
figure that one out for yourself.
More information about the Tutor