2016-11-04 31 views
0

好的,去了Python.com,並加載了這個頁面 https://docs.python.org/3.6/library/turtle.html Turtle Coding的基礎知識。來自Python網站的龜代碼不工作

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() 

嗯,我想這個代碼我自己,這是行不通的。我收到一條錯誤消息,說ExternalError:TypeError:無法讀取第2行未定義的屬性「應用」

我錯過了什麼嗎?我相信我正在運行Python 3.6。我得說,它不會激發出很大的信心從Python網站似乎什麼時候不工作...

UPDATE

好吧,我跟老師在我的Python類和顯然我們使用的「Python」程序與實際的Python稍有不同。我不確定,但我認爲他們說這是通過Javescript模擬的。所以,我不得不添加更基本的東西,像「龜進口」,名龜等

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() 

當我運行這個程序,它繪製一條線,變成烏龜說:「AttributeError錯誤:「龜'object has no attribute'xpos'on line 9「

+1

您提供運行原樣Python3和Python2下我的系統上的代碼。您引用的錯誤消息似乎最經常與JavaScript相關聯,而不是Python - 您能否提供代碼執行的抄本,包括產生的錯誤消息? – cdlane

+0

這有幫助嗎? http://i.imgur.com/pK3qc3d.jpg – Mallan627

+0

我看着你的頁面圖像,看着ActiveCode。它支持Python和JavaScript(以及其他語言),並使用像'language:python'這樣的標籤擴展到'