Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

step bug in turtle's for loop #87455

Closed
Yehuda mannequin opened this issue Feb 21, 2021 · 6 comments
Closed

step bug in turtle's for loop #87455

Yehuda mannequin opened this issue Feb 21, 2021 · 6 comments
Labels
3.9 only security fixes type-bug An unexpected behavior, bug, or error

Comments

@Yehuda
Copy link
Mannequin

Yehuda mannequin commented Feb 21, 2021

BPO 43289
Nosy @terryjreedy, @sweeneyde

Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.

Show more details

GitHub fields:

assignee = None
closed_at = <Date 2021-02-27.02:41:41.829>
created_at = <Date 2021-02-21.21:29:59.509>
labels = ['type-bug', 'invalid', '3.9']
title = "step bug in turtle's for loop"
updated_at = <Date 2021-02-27.07:55:45.656>
user = 'https://bugs.python.org/Yehuda'

bugs.python.org fields:

activity = <Date 2021-02-27.07:55:45.656>
actor = 'Yehuda'
assignee = 'none'
closed = True
closed_date = <Date 2021-02-27.02:41:41.829>
closer = 'terry.reedy'
components = []
creation = <Date 2021-02-21.21:29:59.509>
creator = 'Yehuda'
dependencies = []
files = []
hgrepos = []
issue_num = 43289
keywords = []
message_count = 6.0
messages = ['387472', '387474', '387483', '387508', '387761', '387771']
nosy_count = 3.0
nosy_names = ['terry.reedy', 'Dennis Sweeney', 'Yehuda']
pr_nums = []
priority = 'normal'
resolution = 'not a bug'
stage = 'resolved'
status = 'closed'
superseder = None
type = 'behavior'
url = 'https://bugs.python.org/issue43289'
versions = ['Python 3.9']

@Yehuda
Copy link
Mannequin Author

Yehuda mannequin commented Feb 21, 2021

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.

@Yehuda Yehuda mannequin added 3.9 only security fixes type-bug An unexpected behavior, bug, or error labels Feb 21, 2021
@Yehuda
Copy link
Mannequin Author

Yehuda mannequin commented Feb 21, 2021

Correction to my msg387472: Every *even* step crashes the code.

@sweeneyde
Copy link
Member

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.

@Yehuda
Copy link
Mannequin Author

Yehuda mannequin commented Feb 22, 2021

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\>


@terryjreedy
Copy link
Member

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.

@Yehuda
Copy link
Mannequin Author

Yehuda mannequin commented Feb 27, 2021

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\>


@ezio-melotti ezio-melotti transferred this issue from another repository Apr 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.9 only security fixes type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

2 participants