This is due to a change in the semantics of the division between the 2.X and 3.X versions of Python.
In Python 2.X operations between integers always return an integer, so that 6/10
is interpreted as the entire division - and thus rounded to zero. It is necessary to convert one of the operands to float to make the division into floating point: 6.0/10
or 6/10.0
. This behavior was "inherited" from C-type languages.
In Python 3.X the division between integers can return a floating point. To make an entire division in this version you need to use another operator: 6//10
. This behavior is most common in modern languages, especially dynamic typing.
The entire division operator works also in Python 2.X - and it returns an integer even when its operands are floats: 6.0 // 10.0
will give zero. Already the common division operator (called "true Division") maintains the default behavior of its version, for compatibility, but if you want to use the new semantics in Python 2.X just do the following import:
from __future__ import division
From there, the division will work as in 3.X (if this needs to be done in each source file or not, I’m not sure, I would have to test or consult some reference).
Source
No idea, with me it worked http://ideone.com/WN9h4h. I find it hard to go wrong.
– Maniero
@bigown use Linux. Does it have something to do?
– ropbla9
ideone also uses. And it could not make a difference depending on the OS.
– Maniero
Meanwhile you can help the ganete to create the new site for IT subjects that are not programming. Commit (don’t forget to confirm the email). If you have the minimum number of interested parties, the site will be created. And if you can point to other people, too, that would be even nicer. http://area51.stackexchange.com/proposals/84282/super-user-em-portugues?referrer=iQLJgvwwKWiaSZMVw5WkVIw2. If you would like to know more details, please see: http://meta.pt.stackoverflow.com/q/2482/101 log in to let me know that you have read it and I can delete it.
– Maniero
@mustache I’ll send 1 print
– ropbla9
@bigown updated the answer with the print!
– ropbla9
@bigown What is this?!
– ropbla9