我对这个程序的目标是习惯 python 的内置“乌龟”方法。我的目标是让四只(忍者)乌龟同时在一个广场上行走。虽然我的程序中没有绝对错误,但我希望程序显示海龟同时行走(不会相互碰撞)。起初,我试图在同一行用逗号分隔四个变量——但这并没有改变任何东西。或者,我使用“+”来分隔每个变量——这不起作用。然后我查找了如何同时移动两只乌龟。但是,由于这些程序中的大多数都涉及赛车,因此某些方法不起作用。
import turtle
leonardo = turtle.Turtle()
rafael = turtle.Turtle()
michelangelo = turtle.Turtle()
donatello = turtle.Turtle()
leonardo.shape("turtle")
rafael.shape("turtle")
michelangelo.shape("turtle")
donatello.shape("turtle")
michelangelo.left(90)
donatello.right(90)
leonardo.forward(250)
rafael.backward(250)
donatello.forward(250)
michelangelo.forward(250)
# Better if I could make all four turtles turn at the same time
michelangelo.left(45), leonardo.left(135), rafael.right(45), donatello.left(135)
turtle_speed = 1
angle = float(input("Which angle would you like the turtles to face? "))
for i in range(1):
leonardo.speed(1)
leonardo.pencolor("light green")
leonardo.forward(353.5533905932738)
leonardo.left(angle)
leonardo.forward(353.5533905932738)
leonardo.left(angle)
leonardo.forward(353.5533905932738)
leonardo.left(angle)
leonardo.forward(353.5533905932738)
leonardo.left(angle)
rafael.pencolor("gold")
rafael.forward(353.5533905932738)
rafael.left(angle)
rafael.forward(353.5533905932738)
rafael.left(angle)
rafael.forward(353.5533905932738)
rafael.left(angle)
rafael.forward(353.5533905932738)
rafael.left(angle)
michelangelo.pencolor("turquoise")
michelangelo.left(90)
michelangelo.forward(353.5533905932738)
michelangelo.left(angle)
michelangelo.forward(353.5533905932738)
michelangelo.left(angle)
michelangelo.forward(353.5533905932738)
michelangelo.left(angle)
michelangelo.forward(353.5533905932738)
michelangelo.left(angle)
donatello.pencolor("white")
donatello.forward(353.5533905932738)
donatello.left(angle)
donatello.forward(353.5533905932738)
donatello.left(angle)
donatello.forward(353.5533905932738)
donatello.left(angle)
donatello.forward(353.5533905932738)
donatello.left(angle)
turtle.done()