Issue35672
Created on 2019-01-06 12:34 by Jorge Teran, last changed 2022-04-11 14:59 by admin. This issue is now closed.
| Messages (6) | |||
|---|---|---|---|
| msg333107 - (view) | Author: Jorge Teran (Jorge Teran) | Date: 2019-01-06 12:34 | |
The following code produces an error in the diivision in python 3.5, 3.7 works in python 2.7 import math import sys x=int(1000112004278059472142857) y1=int(1000003) y2=int(1000033) y3=int(1000037) y4=int(1000039) print (int(y1y2y3y4)) print (x) #this product equals x Correct print (int(y2y3*y4)) n=int(x / y1) print (n) #n is an incorrect answer #works in pythoin 2.7 #Gives an incorrect answe in python 3.6.7, 3.7.1 |
|||
| msg333108 - (view) | Author: Serhiy Storchaka (serhiy.storchaka) * ![]() |
Date: 2019-01-06 12:37 | |
I got: NameError: name 'y1y2y3y4' is not defined. |
|||
| msg333109 - (view) | Author: Yash Aggarwal (FR4NKESTI3N) * | Date: 2019-01-06 12:53 | |
@Jorge Teran The division operator was changed in python 3. Now, if you use '/' for division between ints, the result would still be float. To get the same effect as python 2.x, you will have to use '//', i.e. floor division |
|||
| msg333110 - (view) | Author: Jorge Teran (Jorge Teran) | Date: 2019-01-06 12:55 | |
Thanks El dom., 6 de ene. de 2019 08:53, Yash Aggarwal <report@bugs.python.org> escribió: > > Yash Aggarwal <aggarwal.yash2011@gmail.com> added the comment: > > @Jorge Teran > The division operator was changed in python 3. Now, if you use '/' for > division between ints, the result would still be float. To get the same > effect as python 2.x, you will have to use '//', i.e. floor division > > ---------- > nosy: +FR4NKESTI3N > > _______________________________________ > Python tracker <report@bugs.python.org> > <https://bugs.python.org/issue35672> > _______________________________________ > |
|||
| msg333112 - (view) | Author: Steven D'Aprano (steven.daprano) * ![]() |
Date: 2019-01-06 13:42 | |
There is no need to call int() on a literal int: 1000003 is already an int, calling int() on it is just wasting time and making confusing code. print (int(y1y2y3y4)) gives a NameError, since you don't have a variable "y1y2y3y4" defined. Please don't retype your example code from memory, make sure it works and then copy and paste code we can actually run. I think we can simplify your example to this: x = 1000112004278059472142857 y = 1000003 print(x/y) print(int(x/y)) which correctly prints 1.0001090039510477e+18 1000109003951047619 as the division operator uses floating point division in Python 3. Use the floor-division operator // to duplicate the Python 2 behaviour for ints. Closing this as not a bug. |
|||
| msg333180 - (view) | Author: Guido van Rossum (gvanrossum) * ![]() |
Date: 2019-01-07 17:51 | |
For reference, the OP reported the issue initially at https://github.com/python/psf-infra-meta/issues/17 (but it was closed because that's not the right tracker). The y1y2y3y4 etc. are multiplications (mangled by not quoting the code in GitHub and then copy/paste from the rendered code). |
|||
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2022-04-11 14:59:10 | admin | set | github: 79853 |
| 2019-01-07 17:51:53 | gvanrossum | set | nosy:
+ gvanrossum messages: + msg333180 |
| 2019-01-06 13:42:11 | steven.daprano | set | status: open -> closed nosy:
+ steven.daprano resolution: not a bug |
| 2019-01-06 12:55:24 | Jorge Teran | set | messages: + msg333110 |
| 2019-01-06 12:53:45 | FR4NKESTI3N | set | nosy:
+ FR4NKESTI3N messages: + msg333109 |
| 2019-01-06 12:37:52 | serhiy.storchaka | set | nosy:
+ serhiy.storchaka messages: + msg333108 |
| 2019-01-06 12:34:02 | Jorge Teran | create | |
