Files
lab_iteration/square.py
njmason2 79e763b9e7 square.py
I put documentation in my code, explaining each line.
I hadn't written code in 12 months, so I had to refresh my previous learning.
You have to think logically, unlike computers, which don't think at all!
For larger programs, draw a flowchart!
2025-09-07 16:05:04 -04:00

22 lines
831 B
Python

from turtle import *
sizes = [20, 40, 60, 80, 100] # list
for size in sizes: # outer loop, different square sizes from list
def square(): # function definition
for x in range(0,4): # inner loop creating a square
forward(size) # size doesn't change until the outer loop is executed
right(90) # right turn 90 degrees
# this code block for the outer loop (below) has to be
# precisely indented in line with the def square(): function definition,
# otherwise it won't run properly
pendown() # same starting point for each square
color('blue')
square() # first calling and drawing of a square side from the inner loop,
# then drawing a different square size from the "for loop" outer loop
penup()
input() # pause the turtle display screen to see the drawing