Python turtle won't create multiple squares

I tried to play around with this code many times but I can't create multiple squares. This is the problem:

Write a function named drawSquares that calls drawSquare to draw a specified number of squares. The function drawSquares takes four parameters: a turtle t, an integer size, an integer num, the number of squares to draw, and an integer angle, the clockwise rotation between successive squares

For example, the following would be correct output.

import turtle

s = turtle.Screen()

snapper = turtle.Turtle()

drawSquares(snapper, 100, 4, 20)

import turtle

s = turtle.Screen()
t = turtle.Turtle()

def drawSquares(t, size, num, angle):

for i in range(num):
    for x in range(num):
        t.forward(size)
        t.right(angle)

t.forward(size)

drawSquares(t, 100, 4, 20)

如果我理解正确,那么这段代码应该完全按照你的意思去做:

import turtle

s = turtle.Screen()
t = turtle.Turtle()

def drawSquares(t, size, num, angle):

    for i in range(num):
        for x in range(4):
            turtle.forward(size)
            turtle.left(90)
        turtle.right(angle)

drawSquares(t, 100, 4, 20)
链接地址: http://www.djcxy.com/p/80714.html

上一篇: 带递归的多线程Python乌龟

下一篇: Python龟不会创建多个方块