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)
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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started