在 python 中使用 for 循环绘制正方形?
Draw a square using for loops in python?
import turtle
def Draw_turtle(my_turtle):
for i in range(1,5):
my_turtle.turtle.forward(100)
my_turtle.turtle.right(90)
window = turtle.Screen()
window.bgcolor('green')
Alex = turtle.Turtle()
Alex.color('black')
Alex.speed(2)
Alex.shape('triangle')
Draw_turtle(Alex)
我对编码一无所知,当我运行上面的代码没有任何反应。谁能帮帮我。
你的大部分作品都是正确的,而且顺序大致正确。我们只需要在缩进、用法和样式方面稍微调整一下您的代码:
import turtle
def draw_square(my_turtle):
for i in range(4):
my_turtle.forward(100)
my_turtle.right(90)
window = turtle.Screen()
window.bgcolor('green')
alex = turtle.Turtle()
alex.color('black')
alex.speed('slow')
alex.shape('triangle')
draw_square(alex)
window.mainloop()
import turtle
def Draw_turtle(my_turtle):
for i in range(1,5):
my_turtle.turtle.forward(100)
my_turtle.turtle.right(90)
window = turtle.Screen()
window.bgcolor('green')
Alex = turtle.Turtle()
Alex.color('black')
Alex.speed(2)
Alex.shape('triangle')
Draw_turtle(Alex)
我对编码一无所知,当我运行上面的代码没有任何反应。谁能帮帮我。
你的大部分作品都是正确的,而且顺序大致正确。我们只需要在缩进、用法和样式方面稍微调整一下您的代码:
import turtle
def draw_square(my_turtle):
for i in range(4):
my_turtle.forward(100)
my_turtle.right(90)
window = turtle.Screen()
window.bgcolor('green')
alex = turtle.Turtle()
alex.color('black')
alex.speed('slow')
alex.shape('triangle')
draw_square(alex)
window.mainloop()