运行结果:
代码:
import turtle
# 创建海龟对象
n=int(input())
t = turtle.Turtle()
# 设置海龟的颜色和线条粗细
t.color('blue')
t.pensize(3)
# 画四条直线
lengths=10
for j in range(n):
for i in range(4):
lengths+=20
t.forward(lengths)
# 旋转90度
t.left(90)
for i in range(2):
lengths+=20
t.forward(lengths)
t.left(90)
turtle.done()