-2
現在我正在使用libraty Turtle在Python中做一個簡單的視頻遊戲,但是出現了這個錯誤,我不知道如何解決它。我在我的Python代碼中出現錯誤
我的代碼是在這裏:
pastebin.com/wu5jM0gT
錯誤:
Traceback (most recent call last):
File "C:/Users/ricar/PycharmProjects/Juego/Juego.py", line 122, in <module>
objetivo.movimiento()
File "C:/Users/ricar/PycharmProjects/Juego/Juego.py", line 91, in movimiento
self.forward(self.speed)
File "C:\Python27\lib\lib-tk\turtle.py", line 1553, in forward
self._go(distance)
File "C:\Python27\lib\lib-tk\turtle.py", line 1520, in _go
ende = self._position + self._orient * distance
File "C:\Python27\lib\lib-tk\turtle.py", line 277, in __mul__
return Vec2D(self[0]*other, self[1]*other)
TypeError: unsupported operand type(s) for *: 'float' and 'instancemethod'`
有什麼建議?
是'self.speed'多少?請將您的代碼包含在問題中,使用「{}」按鈕格式化,而不是作爲鏈接。 – Ryan
在第91行,你將'Turtle.speed'傳遞給forward函數。由於速度是烏龜的一種實例方法,而不是預期的數值,因此會出現該錯誤。您可能希望'self.forward(self.speed())'調用速度,不帶任何參數將當前速度作爲數字返回,然後'forward'快樂。 – msw