Help with some python homework...

Gregory Ewing greg.ewing at canterbury.ac.nz
Fri Jan 31 03:17:42 EST 2014


sjud9227 wrote:
> Doesn't
> assigning seconds/(60*60) mean that calculating 6*hours will give me 6 hours
> in seconds?

No, it's giving you 6 seconds in hours. (That should
give you a clue as to what you should have done
instead. :-)

Also, I don't know what you were trying to do with
these two statements:

      seconds = seconds - hours*60*60

      seconds = seconds - minutes *60

but they don't belong there at all. If you simply
take them out, that part of the program is almost
right.

> Also, why calculate how many seconds from midnight?

Because the question asked "what time do I get home?",
not "how long did it take me to get home?".

You're already calculating "what time do I get home"
with:

    total_time_run = miles_run_easy_pace + miles_run_fast_pace + time_left_house

except that 'total_time_run' would be better called
something like 'time_got_home'.

> Also, for the life of
> me I cannot figure out how to make everything display in hh:mm:ss.

Here are a few hints:

1. Consider that if you take a number of seconds and
divide it by the number of seconds in an hour, the
quotient is the number of hours, and the remainder is
the number of minutes and seconds left over, expressed
in seconds.

2. If you then divide the remainder from (1) by the
number of seconds in a minute, the quotient is the
number of minutes, and the remainder is the number of
seconds.

3. Python has the following operators for performing
integer division:

    a // b gives the quotient of dividing a by b

    a % b gives the remainder

(I recommend using '//' rather than just '/', because
in some versions of Python, a/b does floating point
division even if a and b are both integers, and that's
not what you want here.)

-- 
Greg



More information about the Python-list mailing list