generated from mwc/lab_iteration
Made the square repeat using a list iteration
It wasnt difficult, it just took some time to figure out how to write it. I used the previous code for how they repeated the square but changed its size to understand how to write the correct code.
This commit is contained in:
14
square.py
14
square.py
@@ -1,17 +1,17 @@
|
|||||||
from turtle import *
|
from turtle import *
|
||||||
|
|
||||||
def square(side_length):
|
def square(side_length):
|
||||||
|
repeat = [1, 2, 3, 4]
|
||||||
|
for repeat in repeat:
|
||||||
forward(side_length)
|
forward(side_length)
|
||||||
right(90)
|
right(90)
|
||||||
forward(side_length)
|
|
||||||
right(90)
|
|
||||||
forward(side_length)
|
|
||||||
right(90)
|
|
||||||
forward(side_length)
|
|
||||||
right(90)
|
|
||||||
|
|
||||||
sizes = [20, 40, 60, 80, 100]
|
sizes = [20, 40, 60, 80, 100]
|
||||||
for size in sizes:
|
for size in sizes:
|
||||||
square(size)
|
square(20)
|
||||||
|
penup()
|
||||||
|
forward(40)
|
||||||
|
pendown()
|
||||||
input()
|
input()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user