created a list and for loop statement using forward and right once rather than four times. Added penup, pendown, and adjusted sizes list.

Checkpoint 1: It was not super difficult trying to rewrite the square() using a for - loop. I have taken a computer science course already so I am a little familiar with the for - loop statements. At first I did use the in range (4) command from my background knowledge of computer science but then after I adjusted my sizes = [20,20,20,20] to create the four boxes, I realized I could create a list that would represent the four sides of a square to use the list iteration and for loop after the list. Figuring out the second part of the problem was helpful for me to figure out the top part instead of using the in range () command.
This commit is contained in:
erbrown
2025-09-14 16:03:30 -04:00
parent 9705646064
commit 9ee9e17edb

View File

@@ -1,17 +1,18 @@
from turtle import *
def square(side_length):
sides = [1,1,1,1]
for side in sides:
forward(side_length)
right(90)
forward(side_length)
right(90)
forward(side_length)
right(90)
forward(side_length)
right(90)
right (90)
sizes = [20, 40, 60, 80, 100]
sizes = [20,20,20,20]
for size in sizes:
square(size)
penup()
forward(40)
pendown()
input()