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: step bug in turtle's for loop
Type: behavior Stage: resolved
Components: Versions: Python 3.9
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: Dennis Sweeney, Yehuda, terry.reedy
Priority: normal Keywords:

Created on 2021-02-21 21:29 by Yehuda, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Messages (6)
msg387472 - (view) Author: Yehuda Katz (Yehuda) Date: 2021-02-21 21:29
from turtle import *

col = ["black", "white"]

for rad in range(40, 0, -1): 
    dot(5*rad, col[rad % 2])
    
done()
======================
Any other step than -1 crashes the code.

Thank you.
msg387474 - (view) Author: Yehuda Katz (Yehuda) Date: 2021-02-21 22:04
Correction to my msg387472: Every *even* step crashes the code.
msg387483 - (view) Author: Dennis Sweeney (Dennis Sweeney) * (Python committer) Date: 2021-02-22 01:21
If I understand correctly, changing the -1 to a -2 does not actually make the program "crash" -- you just only see one black circle.

The reason is that range(40, 0, -2) produces 40, 38, 36, etc., all of which are even numbers, so rad % 2 is always 0, so col[rad % 2] is always "black". You could try:

    for index, rad in enumerate(range(40, 0, -2)): 
        dot(5*rad, col[index % 2])

In the future, I would suggest asking questions like this on StackOverflow, since this is not a bug in Python itself.
msg387508 - (view) Author: Yehuda Katz (Yehuda) Date: 2021-02-22 09:50
Thank you Dennis for taking the time to answer.
Yehuda

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

On Mon, Feb 22, 2021 at 3:21 AM Dennis Sweeney <report@bugs.python.org>
wrote:

>
> Dennis Sweeney <sweeney.dennis650@gmail.com> added the comment:
>
> If I understand correctly, changing the -1 to a -2 does not actually make
> the program "crash" -- you just only see one black circle.
>
> The reason is that range(40, 0, -2) produces 40, 38, 36, etc., all of
> which are even numbers, so rad % 2 is always 0, so col[rad % 2] is always
> "black". You could try:
>
>     for index, rad in enumerate(range(40, 0, -2)):
>         dot(5*rad, col[index % 2])
>
> In the future, I would suggest asking questions like this on
> StackOverflow, since this is not a bug in Python itself.
>
> ----------
> nosy: +Dennis Sweeney
>
> _______________________________________
> Python tracker <report@bugs.python.org>
> <https://bugs.python.org/issue43289>
> _______________________________________
>
msg387761 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2021-02-27 02:41
Yehuda, one can also ask questions like this on python-list.

In the future, when responding by email, please delete the message being responded to, so it does not get repeated when posted to the web page.
msg387771 - (view) Author: Yehuda Katz (Yehuda) Date: 2021-02-27 07:55
Thank you Terry, and take care.

Yehuda

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

On Sat, Feb 27, 2021 at 4:41 AM Terry J. Reedy <report@bugs.python.org>
wrote:

>
> Terry J. Reedy <tjreedy@udel.edu> added the comment:
>
> Yehuda, one can also ask questions like this on python-list.
>
> In the future, when responding by email, please delete the message being
> responded to, so it does not get repeated when posted to the web page.
>
> ----------
> nosy: +terry.reedy
> resolution:  -> not a bug
> stage:  -> resolved
> status: open -> closed
>
> _______________________________________
> Python tracker <report@bugs.python.org>
> <https://bugs.python.org/issue43289>
> _______________________________________
>
History
Date User Action Args
2022-04-11 14:59:41adminsetgithub: 87455
2021-02-27 07:55:45Yehudasetmessages: + msg387771
2021-02-27 02:41:41terry.reedysetstatus: open -> closed

nosy: + terry.reedy
messages: + msg387761

resolution: not a bug
stage: resolved
2021-02-22 09:50:13Yehudasetmessages: + msg387508
2021-02-22 01:21:52Dennis Sweeneysetnosy: + Dennis Sweeney
messages: + msg387483
2021-02-21 22:04:09Yehudasetmessages: + msg387474
2021-02-21 21:29:59Yehudacreate