This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: 7/200 and 7%200 show weird results
Type: Stage:
Components: Versions:
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: Henry.Eshbaugh, eric.smith, georg.brandl, mark.dickinson
Priority: normal Keywords:

Created on 2010-10-21 11:21 by Henry.Eshbaugh, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Messages (5)
msg119274 - (view) Author: Henry Eshbaugh (Henry.Eshbaugh) Date: 2010-10-21 11:21
This may be happening with other numbers, but I got weird results with the modulus and division operators, after I imported the math module. I tried to do 7/200 and got 0, and 200%7 yielded 7, an impossibility with modulus.
msg119275 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2010-10-21 11:24
The result of 7 / 200 is easy to explain -- this is how integer division works in Python 2.  (To get a floating result, one of the numbers must be a float.)

200 % 7 giving 7 however is strange.  Are you sure this is what you calculated?
msg119279 - (view) Author: Eric V. Smith (eric.smith) * (Python committer) Date: 2010-10-21 12:04
Which version of python? Could you run this from the command line and paste the complete session, including the version info that python prints on startup?
msg119299 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2010-10-21 14:02
Seconding Eric's comment.  This is what I get on my machine;  can you cut and paste the equivalent output on yours (including whatever else is required to reproduce the results you describe)

Python 2.6.1 (r261:67515, Feb 11 2010, 15:47:53) 
[GCC 4.2.1 (Apple Inc. build 5646)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> 200 % 7
4

In any case, please let us know which version of Python you're using, and where you got it from.
msg119300 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2010-10-21 14:11
The bug title interestingly says "7%200", which does result in 7.  I therefore think the OP just confused the order of operands for "%".
History
Date User Action Args
2022-04-11 14:57:07adminsetgithub: 54372
2010-10-21 14:11:56georg.brandlsetstatus: open -> closed
resolution: not a bug
messages: + msg119300
2010-10-21 14:02:09mark.dickinsonsetmessages: + msg119299
2010-10-21 12:04:32eric.smithsetnosy: + mark.dickinson, eric.smith
messages: + msg119279
2010-10-21 11:24:21georg.brandlsetnosy: + georg.brandl
messages: + msg119275
2010-10-21 11:21:47Henry.Eshbaughcreate