classification
Title: Phone Number Generator
Type: behavior Stage: resolved
Components: Versions:
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: Braiden Gole, josh.r, steven.daprano, terry.reedy
Priority: normal Keywords:

Created on 2018-05-02 01:31 by Braiden Gole, last changed 2018-05-02 05:49 by steven.daprano. This issue is now closed.

Files
File name Uploaded Description Edit
Phone_numbers.PNG Braiden Gole, 2018-05-02 01:31 Photo of an error
Messages (4)
msg316031 - (view) Author: Braiden Gole (Braiden Gole) Date: 2018-05-02 01:31
I was creating a small program to generate numbers for fun and I realized that my output is different from my input. The random phone number that I used is: (519-662-6963) and what I get is: (519-662-6953), where the second last digit changes, thought it would be worth looking at. Everything looks to be inline and in order of precedence but not sure what is going on.
msg316032 - (view) Author: Josh Rosenberg (josh.r) * (Python triager) Date: 2018-05-02 01:40
You named your loop variable i, overlapping the name of your second to last digit, so you end up replacing the original value of i in each (given the break, the only) loop.

So before the loop begins, i has the expected value of '6', but on the first iteration, i is rebound to the value of a (the first element in the tuple), '5', and your format string uses that value instead. If you removed the break, you'd see the second to last digit cycle through all the other values as it goes, because i would be repeatedly rebound to each digit as it goes.

This is a bug in your code, not a problem with Python; in the future, direct questions of this sort to other online resources (e.g. Stack Overflow); unless you have a provable bug in Python itself, odds are it's a bug in your code's logic.
msg316036 - (view) Author: Braiden Gole (Braiden Gole) Date: 2018-05-02 02:41
Thanks for the detailed explenation and my apologies. I will contact
Stack Overflow in the future when I have an issue. This is my first report
in the bug section of Python and I now understand the content that needs to
be put under a category like this one.

Thanks: Braiden Gole

On Tue, May 1, 2018, 9:40 PM Josh Rosenberg, <report@bugs.python.org> wrote:

>
> Josh Rosenberg <shadowranger+python@gmail.com> added the comment:
>
> You named your loop variable i, overlapping the name of your second to
> last digit, so you end up replacing the original value of i in each (given
> the break, the only) loop.
>
> So before the loop begins, i has the expected value of '6', but on the
> first iteration, i is rebound to the value of a (the first element in the
> tuple), '5', and your format string uses that value instead. If you removed
> the break, you'd see the second to last digit cycle through all the other
> values as it goes, because i would be repeatedly rebound to each digit as
> it goes.
>
> This is a bug in your code, not a problem with Python; in the future,
> direct questions of this sort to other online resources (e.g. Stack
> Overflow); unless you have a provable bug in Python itself, odds are it's a
> bug in your code's logic.
>
> ----------
> nosy: +josh.r
>
> _______________________________________
> Python tracker <report@bugs.python.org>
> <https://bugs.python.org/issue33404>
> _______________________________________
>
msg316044 - (view) Author: Steven D'Aprano (steven.daprano) * (Python committer) Date: 2018-05-02 05:49
Hi Braiden, and welcome!

I see that the ticket has already been closed, but another note for the future: please don't paste screenshots of your code, copy and paste the relevant source code. We don't edit code with Photoshop, and posting images makes it hard to copy the source for additional testing, and prevents those who are blind or visually impaired from getting involved.
History
Date User Action Args
2018-05-02 05:49:33steven.dapranosetnosy: + steven.daprano
messages: + msg316044
2018-05-02 02:41:05Braiden Golesetmessages: + msg316036
2018-05-02 02:02:55zach.waresetcomponents: - IDLE
2018-05-02 02:02:38zach.waresetassignee: terry.reedy ->
2018-05-02 02:02:32zach.waresetstatus: open -> closed
resolution: not a bug
stage: resolved
2018-05-02 01:40:52josh.rsetversions: - Python 3.6
2018-05-02 01:40:27josh.rsetnosy: + josh.r
messages: + msg316032
2018-05-02 01:31:33Braiden Golecreate