Help with some python homework...
Scott W Dunning
swdunning at cox.net
Fri Jan 31 20:14:31 EST 2014
Thanks Chris!
So, this is what I came up with. It works, which is good but it’s a little different from a few things you guys had mentioned. For one, I got the correct time by calculating the number of time run and converting that into seconds then back out to hr:mn:sc. I didn’t calculate from midnight. That seemed more complicated to me because I’d have to figure the number of seconds from midnight to 6:52am then do the calculations for number of seconds run until I got home, then I got kind of lost. Also, before I forget what is the difference between / and //? I remember something about floor division? Not sure what that means though. Is it like a % where it gives the remainder after dividing? Thanks again. Code below. Also, I think I found out through a little trial and error that I had two different hours, mins, and sec so I had to use one uppercase and one lower case. Is that frowned upon? And should I have come up with a different name instead?
SECONDS = 1
MINUTES = 60 * SECONDS
HOURS = 60 * MINUTES
time_left_house = 6 * HOURS + 52 * MINUTES
miles_run_easy_pace = 2 * (8 * MINUTES + 15 * SECONDS)
miles_run_fast_pace = 3 * (7 * MINUTES + 12 * SECONDS)
time_returned_home = miles_run_easy_pace + miles_run_fast_pace + time_left_house
hours = time_returned_home // HOURS
part_hour = time_returned_home % HOURS
minutes = part_hour // MINUTES
seconds = part_hour % MINUTES
print "Time returned home:", hours,":", minutes,":", seconds,”am"
On Jan 31, 2014, at 5:57 PM, Chris Angelico <rosuav at gmail.com> wrote:
> On Sat, Feb 1, 2014 at 11:42 AM, Scott W Dunning <swdunning at cox.net> wrote:
>> Also, any help on how to get the hours and seconds into double digits that would be cool too. 00:00:00
>
> Once you can divide the number of seconds into hours, minutes, and
> seconds, you can format them like this:
>
> time = "%02d:%02d:%02d" % (hours, minutes, seconds)
>
> I'll give you that one for free because I don't think it's
> particularly critical to your course, but it will look better that way
> :) Look up the string formatting features of Python in the docs.
>
> ChrisA
> --
> https://mail.python.org/mailman/listinfo/python-list
More information about the Python-list
mailing list