Python 2.7.6 help with modules
Chris Angelico
rosuav at gmail.com
Sun Feb 9 23:30:55 EST 2014
More information about the Python-list mailing list
Sun Feb 9 23:30:55 EST 2014
- Previous message (by thread): Python 2.7.6 help with modules
- Next message (by thread): Python 2.7.6 help with modules
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On Mon, Feb 10, 2014 at 3:17 PM, Scott W Dunning <swdunning at 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
- Previous message (by thread): Python 2.7.6 help with modules
- Next message (by thread): Python 2.7.6 help with modules
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
More information about the Python-list mailing list