Lesson 16: Nested loops with Turtle

posted Feb 11, 2020, 8:01 AM by Attila Lengyel   [ updated Feb 11, 2020, 8:02 AM ]
import turtle as t
import random as r

goo = t.Turtle()
goo.speed(0)
colors = ['red', 'orange', 'magenta', 'green', 'blue', 'yellow']

for k in range(0,8):
for i in range(0,8):
x = -180 + i * 50
y = 180 - k * 50
goo.penup()
goo.setposition(x,y)
goo.pendown()
goo.color(r.choice(colors))
goo.begin_fill()
for j in range(0,4):
goo.right(90)
goo.forward(40)
goo.end_fill()



for i in range(0,5):
for j in range(0,5):
print(i, "x", j, "=", i * j)



Comments