[Python] Turtle Code from the Python website not working

Discussão em 'Python' iniciado por Stack, Abril 8, 2025.

  1. Stack

    Stack Membro Participativo

    Okay, went over to Python.com and loaded up this page https://docs.python.org/3.6/library/turtle.html for Turtle Coding basics.

    Right there they have a code that makes a red and yellow star

    from turtle import *
    color('red', 'yellow')
    begin_fill()
    while True:
    forward(200)
    left(170)
    if abs(pos()) < 1:
    break
    end_fill()
    done()


    Well, I tried this code myself, and it doesn't work. I get an error message saying ExternalError: TypeError: Cannot read property 'apply' of undefined on line 2

    Am I missing something? I'm running Python 3.6 I believe. I gotta say, it does not inspire a lot of confidence when something from the Python website doesn't seem to work...

    UPDATE

    Well, I spoke to the teachers at my Python class and apparently the "Python" program we're using is slightly different than actual Python. I'm not sure but I think they said it's emulated through Javescript.or some such. So, I had to add more basic stuff like "import turtle", name a turtle, etc.

    import turtle
    wn=turtle.Screen
    mark=turtle.Turtle()
    mark.color('red', 'yellow')
    mark.begin_fill()
    while True:
    mark.forward(100)
    mark.left(170)
    if abs(mark.xpos()) < 1:
    break
    end_fill()
    done()


    When I run this program, it draws one line, turns the Turtle and says, “AttributeError: 'Turtle' object has no attribute 'xpos' on line 9”

    Continue reading...

Compartilhe esta Página