Christopher Spears wrote: > 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. > take a look at the divmod built-in function. >
-- Bob Gailer 510-978-4454 _______________________________________________ Tutor maillist - Tutor@python.org http://mail.python.org/mailman/listinfo/tutor