2

I have the following code to play with turtle within turtleworld:

>>> from swampy.TurtleWorld import *
>>> world = TurtleWorld()
>>> bob = Turtle()
>>> fd(bob, 100)
>>> bob.position()
>>> bob.reset()

There is no issue with executing the fd(bob, 100) line but when I try to check turtle position it returns AttributeError:

Traceback (most recent call last):
  File "<pyshell#13>", line 1, in <module>
    bob.position()
AttributeError: 'Turtle' object has no attribute 'position'

Why is this happening? What am I missing? I have read the documentation and it states that both position() and reset() methods should be available.

4

1 回答 1

1

您可能会将turtle模块与swampy.TurtleWorldTurtle类混淆。

turtlemodule中,确实有一个position()方法,但是在swampy.TurtleWorld's Turtleclass中没有,正如@Georgy 在评论中提到的那样。

您可以改为使用bob.get_x()andbob.get_y()作为其 x、y 坐标。

于 2018-05-06T11:54:24.843 回答