[Tutor] no loops
Gregor Lingl
glingl at aon.at
Wed Jul 12 01:13:58 CEST 2006
Christopher Spears schrieb:
IF you know that it's 20000 seconds after midnight,
how many hours, minutes, seconds after midnight ist this.
If you should compute this by hand, how would you proceed?
Best wishes,
Gregor
> I am working on another problem from "How To Think
> Like A Computer Scientist". Here is a function:
>
> def increment(time, seconds):
> time.seconds = time.seconds + seconds
>
> while time.seconds >= 60:
> time.seconds = time.seconds - 60
> time.minutes = time.minutes + 1
>
> while time.minutes >= 60:
> time.minutes = time.minutes - 60
> time.hours = time.hours + 1
>
> Here is the function in action:
>
>
>>>> from time import *
>>>> atime = Time()
>>>> atime.hours = 1
>>>> atime.minutes = 60
>>>> atime.seconds = 120
>>>> printTime(atime)
>>>>
> 1:60:120
>
>>>> increment(atime,1)
>>>> printTime(atime)
>>>>
> 2:2:1
>
> Now the exercise is:
> As an exercise, rewrite this function so that it
> doesn't contain any loops.
>
> I have been staring at this function and drawing a
> blank. Something tells me that I need to use
> iteration, but I am not sure how I could implement it.
>
> -Chris
>
> _______________________________________________
> Tutor maillist - Tutor at python.org
> http://mail.python.org/mailman/listinfo/tutor
>
>
>
More information about the Tutor
mailing list