On the fourth day of Christmas my true love sent to me
four lines of code
three LEDs in cardboard
two functions in a module
and a micro:bit in a Christmas tree

Sorry that this post isn’t very festive.

I challenged myself to create an interesting drawing with Python turtle using only four lines of code – here’s the result.

import turtle
for i in range (100000000):
    turtle.forward(25)
    turtle.left(i*3)

Here’s what the code eventually creates:

capture

Here’s the run-through of the code:

import turtle #import the turtle module
for i in range (100000000): #repeat 100000000 times;
    turtle.forward(25) #move forward 25 pixels
    turtle.left(i*3) #turn left i times three degrees

Do you have a different idea for a pattern made with only four lines of code? Share it here!

Advertisements