Question: Write a program to draw the image shown below by calling drawSquare function. There are five squares to draw. Although you may write five statements

Write a program to draw the image shown below by calling drawSquare function. There are five squares to draw. Although you may write five statements to call drawSquare function, five penup statements, five ..., what if you have to draw twenty squares or even more? Notice that no matter how many squares to be draw in the following image, the process is repeated. Can we use a for loop? Each square has the same size, but starts from different position. Assume the first one starts from (0, 0), the second one (-25, -25), the third one (-50, -50)

Write a program to draw the image shown below by calling drawSquare

import turtle

def drawSquare(t, sz):

"""Make turtle t draw a square with side sz."""

for i in range(4):

t.forward(sz)

t.left(90)

wn = turtle.Screen() # Set up the window and its attributes

wn.bgcolor("lightgreen")

alex = turtle.Turtle() # create alex

alex.color("hotpink") #change pen color to hot pink

alex.pensize(3)

# Contiue your rest of the codes here

wn.exitonclick()

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!