Files
lab_iteration/square.py
erbrown 9ee9e17edb 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.
2025-09-14 16:03:30 -04:00

19 lines
256 B
Python

from turtle import *
def square(side_length):
sides = [1,1,1,1]
for side in sides:
forward(side_length)
right (90)
sizes = [20,20,20,20]
for size in sizes:
square(size)
penup()
forward(40)
pendown()
input()