タートルを別のタートルに移動する必要があるプログラムを作成しています。しかし、単純な:それはother_turtle.pos()
メソッド間法と減算され、浮いが定義されていないことを言うのでカメとother_turtleは2匹のすでに定義されてカメは動作しませんタートルを別のタートルに移動する
ある
turtle.goto(other_turtle.pos())
。だから私は試し続けてother_turtle.pos()
をfloat(other_turtle.pos())
に変更しました。それから、あなたは方法を浮かべることができないと言って、それは間違っていました。
私の質問:これは可能なのですか、これは不可能ですか、またはパイソンカメ自体の限界のために不可能ですか?
コード:
def turtle_clone(clone_nmb):
return [turtle.Turtle() for i in range(clone_nmb)]
def straight_curve(turtle,number_of_arms,number_of_points,colors):
turtles = turtle_clone(2)
turtles[0].hideturtle()
turtles[1].hideturtle()
turtles[0].color(colors[0])
turtles[1].color(colors[0])
pos = 0
for i in range(number_of_arms):
turtles[0].setheading(pos)
turtles[0].forward(5)
turtles[1].setheading(pos+(360/number_of_arms))
turtles[1].forward(5*number_of_points)
turtles[1].right(180)
for i in range(number_of_points):
turtles[0]
turtle.penup()
turtle.goto(turtles[0].xcor,turtles[0].ycor)
turtle.pendown()
turtle.goto(turtles[1].xcor,turtles[1].ycor)
turtles[0].forward(5)
turtles[1].forward(5)
pos += 360/number_of_arms
turtles[0].goto(0,0)
エラーメッセージ:
Traceback (most recent call last):
File "C:\Users\gularson\Documents\Garrett\Messing Around\turtle_functions.py", line 97, in <module>
straight_curve(turt,5,30,["white"])
File "C:\Users\gularson\Documents\Garrett\Messing Around\turtle_functions.py", line 87, in straight_curve
turtle.goto(turtles[0].xcor,turtles[0].ycor)
File "C:\Users\gularson\Documents\Garrett\Python\lib\turtle.py", line 1776, in goto
self._goto(Vec2D(x, y))
File "C:\Users\gularson\Documents\Garrett\Python\lib\turtle.py", line 3165, in _goto
diff = (end-start)
File "C:\Users\gularson\Documents\Garrett\Python\lib\turtle.py", line 262, in __sub__
return Vec2D(self[0]-other[0], self[1]-other[1])
TypeError: unsupported operand type(s) for -: 'method' and 'float'
常に問題になるFULLエラーメッセージ(トレースバック) - あなたの説明よりも便利です。 – furas
あなたは 'pos()'で '()'を使用していますか?あなたの説明から、 'turtle.goto(other_turtle.pos)'を '()'なしで使うように見えます。完全なエラーメッセージとコードを表示してください。 – furas