擅长:python、mysql、java
<p>也许是一种更干净的方式:</p>
<pre><code>import turtle
squares = 5 # Choose how many squares
scale = 20 # Chose the scale of the squares
t = turtle.Turtle()
for i in range(squares+1):
for _ in range(4):
t.pendown()
t.forward(scale*i)
t.right(90)
t.penup()
t.setpos(t.xcor()-scale/2,t.ycor()+scale/2)
turtle.done()
</code></pre>
<p>输出:</p>
<p><a href="https://i.stack.imgur.com/bjK6Y.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/bjK6Y.png" alt="turtle-graphics"/></a></p>