简单的turtle模块代码python 3.9.7问题

问题描述 投票:0回答:2

我正在测试海龟模块,但命令不起作用。我在 Windows 10 上并下载了 python 3.9.7 这是代码:

>>> import turtle
>>> t = turtle.pen()
>>> t.forward(50)
Traceback (most recent call last):
  File "<pyshell#2>", line 1, in <module>
    t.forward(50)
AttributeError: 'dict' object has no attribute 'forward'
>>> 

此代码打开第二个窗口并显示海龟,但它不会向前移动并显示错误。有谁知道我该如何解决这个问题?

python turtle-graphics python-turtle
2个回答
0
投票

正确的语法是:

import turtle
t = turtle.Turtle() # create a Turtle and assign it to the variable "t"
t.forward(50)

0
投票

回溯(最近一次调用最后一次): 文件“main.py”,第 1 行,位于 导入标题、数学 ModuleNotFoundError:没有名为“tirtle”的模块

** 进程已退出 - 返回代码:1 ** 按 Enter 退出终端

© www.soinside.com 2019 - 2024. All rights reserved.