Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #65105

Re: Help with some python homework...

From Gregory Ewing <greg.ewing@canterbury.ac.nz>
Newsgroups comp.lang.python
Subject Re: Help with some python homework...
Date 2014-01-31 21:17 +1300
Message-ID <bl14h8F21ooU1@mid.individual.net> (permalink)
References <02c4c69d-71f1-4a01-86df-d4d5a7ffb3f5@googlegroups.com> <mailman.6195.1391146214.18130.python-list@python.org> <8da5d692-1446-4107-9a5a-5efd91f7c051@googlegroups.com>

Show all headers | View raw


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

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Help with some python homework... scottwd80@gmail.com - 2014-01-30 21:12 -0800
  Re: Help with some python homework... Chris Angelico <rosuav@gmail.com> - 2014-01-31 16:30 +1100
    Re: Help with some python homework... sjud9227 <scottwd80@gmail.com> - 2014-01-30 22:24 -0800
      Re: Help with some python homework... Chris Angelico <rosuav@gmail.com> - 2014-01-31 17:38 +1100
        Re: Help with some python homework... sjud9227 <scottwd80@gmail.com> - 2014-01-30 22:48 -0800
      Re: Help with some python homework... Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2014-01-31 21:17 +1300
        Re: Help with some python homework... Chris Angelico <rosuav@gmail.com> - 2014-01-31 19:30 +1100
          Re: Help with some python homework... Gregory Ewing <greg.ewing@canterbury.ac.nz> - 2014-01-31 23:46 +1300
        Re: Help with some python homework... Chris Angelico <rosuav@gmail.com> - 2014-02-01 11:57 +1100
        Re: Help with some python homework... Chris Angelico <rosuav@gmail.com> - 2014-02-01 12:34 +1100
        Re: Help with some python homework... David <bouncingcats@gmail.com> - 2014-02-01 14:17 +1100
        Re: Help with some python homework... Scott W Dunning <swdunning@cox.net> - 2014-01-31 18:14 -0700
          Re: Help with some python homework... Denis McMahon <denismfmcmahon@gmail.com> - 2014-02-01 19:32 +0000
            Re: Help with some python homework... David Hutto <dwightdhutto@gmail.com> - 2014-02-02 17:12 -0800
              Re: Help with some python homework... Larry Hudson <orgnut@yahoo.com> - 2014-02-02 23:48 -0800
        Re: Help with some python homework... Scott W Dunning <swdunning@cox.net> - 2014-01-31 17:46 -0700
        Re: Help with some python homework... Scott W Dunning <swdunning@cox.net> - 2014-01-31 17:42 -0700
        Re: Help with some python homework... David <bouncingcats@gmail.com> - 2014-02-01 17:13 +1100
        Re: Help with some python homework... Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2014-02-01 10:44 -0500
  Re: Help with some python homework... Neil Cerutti <neilc@norwich.edu> - 2014-01-31 13:51 +0000
  Re: Help with some python homework... Denis McMahon <denismfmcmahon@gmail.com> - 2014-02-01 03:02 +0000
  Re: Help with some python homework... Scott W Dunning <swdunning@cox.net> - 2014-01-31 17:35 -0700
  Re: Help with some python homework... Scott W Dunning <swdunning@cox.net> - 2014-01-31 22:18 -0700
    Re: Help with some python homework... Denis McMahon <denismfmcmahon@gmail.com> - 2014-02-01 19:45 +0000
    Re: Help with some python homework... David Hutto <dwightdhutto@gmail.com> - 2014-02-02 08:11 -0800
      Re: Help with some python homework... David Hutto <dwightdhutto@gmail.com> - 2014-02-02 08:36 -0800
      Re: Help with some python homework... MRAB <python@mrabarnett.plus.com> - 2014-02-02 16:38 +0000
        Re: Help with some python homework... David Hutto <dwightdhutto@gmail.com> - 2014-02-02 08:57 -0800
          Re: Help with some python homework... Denis McMahon <denismfmcmahon@gmail.com> - 2014-02-02 17:43 +0000
            Re: Help with some python homework... David Hutto <dwightdhutto@gmail.com> - 2014-02-02 10:09 -0800
            Re: Help with some python homework... David Hutto <dwightdhutto@gmail.com> - 2014-02-02 11:08 -0800
              Re: Help with some python homework... David Hutto <dwightdhutto@gmail.com> - 2014-02-02 11:21 -0800
    Re: Help with some python homework... "Rhodri James" <rhodri@wildebst.org.uk> - 2014-02-02 17:15 +0000
  Re: Help with some python homework... Scott W Dunning <swdunning@cox.net> - 2014-01-31 22:04 -0700
  Re: Help with some python homework... Scott W Dunning <swdunning@cox.net> - 2014-01-31 17:07 -0700
  Re: Help with some python homework... Scott W Dunning <swdunning@cox.net> - 2014-01-31 22:19 -0700
  Re: Help with some python homework... Dennis Lee Bieber <wlfraed@ix.netcom.com> - 2014-02-01 10:50 -0500
  Re: Help with some python homework... Scott W Dunning <swdunning@cox.net> - 2014-02-01 23:06 -0700

csiph-web