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


Groups > comp.lang.python > #65799

Re: Python 2.7.6 help with modules

References <032F2E23-6983-4710-B087-C1771B66C3EF@cox.net> <635C857D-1F7A-4F95-B3A7-F1A3C69BF137@cox.net> <1DA52F3B-CE00-4E47-BE84-C07482966FD7@cox.net> <F4033A14-BA16-4897-9998-65D431B5071C@cox.net> <972E1362-8C9D-47BC-BAD7-A0CA754C8D84@cox.net>
Date 2014-02-10 15:30 +1100
Subject Re: Python 2.7.6 help with modules
From Chris Angelico <rosuav@gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.6611.1392006658.18130.python-list@python.org> (permalink)

Show all headers | View raw


On Mon, Feb 10, 2014 at 3:17 PM, Scott W Dunning <swdunning@cox.net> wrote:
> How to do it from the small end up:
>
> time = int(raw_input("Enter number of seconds: "))
> seconds = time % 60
>
> So here it takes say 1000000 and divides it by 60 to put in seconds and
> spits out the remainder?  1000000 / 60 is approximately 16666 with a
> remainder of about 40, which would be the correct amount for seconds.  From
> there I get a little lost.
>
> time /= 60
>
> Then we take the remainder (40) from above and divide that by 60?  Already
> it’s confusing me.

The first part just spits out the remainder, without changing the
base. It'll set seconds to 40 (exactly, not about), but time is still
1000000. Then in the next line, we divide time by 60, which sets it to
that quotient (16666). This is why it's probably clearer to use
divmod, which does both halves (quotient and remainder) at once.

ChrisA

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


Thread

Re: Python 2.7.6 help with modules Chris Angelico <rosuav@gmail.com> - 2014-02-10 15:30 +1100

csiph-web