Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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)

image text in transcribed

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

MySQL Crash Course A Hands On Introduction To Database Development

Authors: Rick Silva

1st Edition

1718503008, 978-1718503007

More Books

Students also viewed these Databases questions