Day 47 - Drawing From a Data File

We will learn to read file one line at a toime, using the data to control the turtle and draw a design.

Finished Code

from turtle import *
screen = Screen()


with open("47_input.txt", "r") as file:
    for line in file:
        arLine = line.split(" ")
        strCmd = arLine[0]
        strP = int(arLine[1])
        if strCmd == "fd":
            forward(strP)
        elif strCmd == "lt":
            left(strP)
        elif strCmd == "rt":
            right(strP)
        elif strCmd == "c":
            circle(strP)
        elif strCmd == "hc":
            circle(strP, 180)
        elif strCmd == "rhc":
            circle(strP, -180)

        print(line, end="")

print("Finished.")


screen.exitonclick()