From 43d3315af692d186fcb3e394858d02b0dba7fc68 Mon Sep 17 00:00:00 2001 From: angelotr Date: Sat, 13 Sep 2025 21:29:39 -0400 Subject: [PATCH] I replaced the four repeated forward and right command with a for-loop that iterates over a list of sides, so each command is written only once while still drawing the same square Checkpoint 1: I found it difficult to rewrite square() using a for-loop. It has been a long time since I took a coding course so I did not remember much from what I did in previous coding courses to apply here. I did a lot of trial and error to see what I remembered about for-loops and if all went wrong I looked online for examples of how a for-loop properly looks. --- square.py | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) diff --git a/square.py b/square.py index f1fb2a2..f741c6a 100644 --- a/square.py +++ b/square.py @@ -1,17 +1,14 @@ from turtle import * def square(side_length): - forward(side_length) - right(90) - forward(side_length) - right(90) - forward(side_length) - right(90) - forward(side_length) - right(90) + + sides = [side_length] * 4 + for side in sides: + forward(side) + right(90) sizes = [20, 40, 60, 80, 100] for size in sizes: square(size) -input() +input()