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: Bug in Python's compiler
Type: compile error Stage: resolved
Components: Windows Versions: Python 3.7
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: Fady shehata, paul.moore, scoder, steve.dower, steven.daprano, tim.golden, tim.peters, zach.ware
Priority: normal Keywords:

Created on 2018-12-27 16:19 by Fady shehata, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
Capture.PNG Fady shehata, 2018-12-27 16:19 Bug in python's compiler
Capture2.PNG Fady shehata, 2018-12-27 16:48
Messages (8)
msg332596 - (view) Author: Fady shehata (Fady shehata) Date: 2018-12-27 16:19
this code is completely right , and its trace is right and give the correct result but your compiler give me an incorrect result. if we input 1010 it must give 10, the compiler give ten but uncollected ten like 11111122 and if we input 111 it's output by your compiler is 1123
msg332597 - (view) Author: Tim Peters (tim.peters) * (Python committer) Date: 2018-12-27 16:34
`input()` returns a string, not a list.  For input '1010' you're effectively computing this:

>>> int('1' * 8) + int('1' * 2) # = 11111111 + 11
11111122

which is the correct answer.  If you want your input to be a list of integers instead of a string, try, e.g.,

a = input("please enter a binary integer ")
a = list(map(int, a))
msg332598 - (view) Author: Stefan Behnel (scoder) * (Python committer) Date: 2018-12-27 16:34
I have no doubts that the code is right. However, your expectations might not be.

Try to print the values inside of the loop, for each iteration, as well as their type. You'll likely be surprised what that gives.

(In any case, this is not a bug. If you need help in understanding what's going on here, please ask on the Python mailing list, or consult a local Python meetup.)
msg332599 - (view) Author: Fady shehata (Fady shehata) Date: 2018-12-27 16:44
you didn't understand me, look, if we put (10) in binary it will give (2)
in decimal because ((0*2**0)+(1*2**1), but it gives the tow like that 11 it
means if we add the digits in the result we will get the right result

<https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail&utm_term=icon>
Virus-free.
www.avast.com
<https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail&utm_term=link>
<#DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2>

On Thu, 27 Dec 2018 at 18:34, Tim Peters <report@bugs.python.org> wrote:

>
> Tim Peters <tim@python.org> added the comment:
>
> `input()` returns a string, not a list.  For input '1010' you're
> effectively computing this:
>
> >>> int('1' * 8) + int('1' * 2) # = 11111111 + 11
> 11111122
>
> which is the correct answer.  If you want your input to be a list of
> integers instead of a string, try, e.g.,
>
> a = input("please enter a binary integer ")
> a = list(map(int, a))
>
> ----------
> nosy: +tim.peters
> resolution:  -> not a bug
> stage:  -> resolved
> status: open -> closed
>
> _______________________________________
> Python tracker <report@bugs.python.org>
> <https://bugs.python.org/issue35597>
> _______________________________________
>
msg332600 - (view) Author: Fady shehata (Fady shehata) Date: 2018-12-27 16:48
look at this if we input (1011) in binary it must give eleven in decimal
but it gives uncollected eleven like 11111123 if we add the digits in this
result we will get the right result eleven
[image: Capture2.PNG]

<https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail&utm_term=icon>
Virus-free.
www.avast.com
<https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail&utm_term=link>
<#DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2>

On Thu, 27 Dec 2018 at 18:34, Tim Peters <report@bugs.python.org> wrote:

>
> Tim Peters <tim@python.org> added the comment:
>
> `input()` returns a string, not a list.  For input '1010' you're
> effectively computing this:
>
> >>> int('1' * 8) + int('1' * 2) # = 11111111 + 11
> 11111122
>
> which is the correct answer.  If you want your input to be a list of
> integers instead of a string, try, e.g.,
>
> a = input("please enter a binary integer ")
> a = list(map(int, a))
>
> ----------
> nosy: +tim.peters
> resolution:  -> not a bug
> stage:  -> resolved
> status: open -> closed
>
> _______________________________________
> Python tracker <report@bugs.python.org>
> <https://bugs.python.org/issue35597>
> _______________________________________
>
msg332601 - (view) Author: Tim Peters (tim.peters) * (Python committer) Date: 2018-12-27 16:50
Please read my answer again.  Your code does not do what you _think_ it does.  It does what I said it does instead.

>>> a = input()
1010
>>> print(a)
1010
>>> print(type(a))
<class 'str'>

The input you're working with is NOT A LIST OF INTEGERS.  It's a string of "0" and "1" CHARACTERS.

And I already told you how to repair that too:

>>> a = list(map(int, a))
>>> a
[1, 0, 1, 0]
>>> type(a)
<class 'list'>
msg332602 - (view) Author: Fady shehata (Fady shehata) Date: 2018-12-27 16:55
yea yea i understand you and you are right thank you and sorry for this
miss understanding 😊

<https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail&utm_term=icon>
Virus-free.
www.avast.com
<https://www.avast.com/sig-email?utm_medium=email&utm_source=link&utm_campaign=sig-email&utm_content=webmail&utm_term=link>
<#DAB4FAD8-2DD7-40BB-A1B8-4E2AA1F9FDF2>

On Thu, 27 Dec 2018 at 18:50, Tim Peters <report@bugs.python.org> wrote:

>
> Tim Peters <tim@python.org> added the comment:
>
> Please read my answer again.  Your code does not do what you _think_ it
> does.  It does what I said it does instead.
>
> >>> a = input()
> 1010
> >>> print(a)
> 1010
> >>> print(type(a))
> <class 'str'>
>
> The input you're working with is NOT A LIST OF INTEGERS.  It's a string of
> "0" and "1" CHARACTERS.
>
> And I already told you how to repair that too:
>
> >>> a = list(map(int, a))
> >>> a
> [1, 0, 1, 0]
> >>> type(a)
> <class 'list'>
>
> ----------
>
> _______________________________________
> Python tracker <report@bugs.python.org>
> <https://bugs.python.org/issue35597>
> _______________________________________
>
msg332623 - (view) Author: Steven D'Aprano (steven.daprano) * (Python committer) Date: 2018-12-27 21:58
For future reference, please don't give screen shots when reporting bugs. Code is text, and we don't edit code with Photoshop.

Copy and paste the text, don't take a screen shot. Screen shots make it impossible to run the code, and they are difficult for the blind and visually impaired who are using a screen-reader.
History
Date User Action Args
2022-04-11 14:59:09adminsetgithub: 79778
2018-12-27 21:58:12steven.dapranosetnosy: + steven.daprano
messages: + msg332623
2018-12-27 16:55:57Fady shehatasetmessages: + msg332602
2018-12-27 16:50:13tim.peterssetmessages: + msg332601
2018-12-27 16:48:44Fady shehatasetfiles: + Capture2.PNG

messages: + msg332600
2018-12-27 16:44:44Fady shehatasetmessages: + msg332599
2018-12-27 16:34:38scodersetnosy: + scoder
messages: + msg332598
2018-12-27 16:34:06tim.peterssetstatus: open -> closed

nosy: + tim.peters
messages: + msg332597

resolution: not a bug
stage: resolved
2018-12-27 16:19:48Fady shehatacreate