[Tutor] Turtle drawing
Roger Lea Scherer
rls4jc at gmail.com
Tue Jun 5 16:46:06 EDT 2018
I give up again. Here's my code which gives no error, but draws something
that looks sort of like a dinosaur. I've included the first few lines of
the text file mystery so you can see the format I received from the
instructions.
Please help. Thank you.
*****Mystery excerpt*****
UP
-218 185
DOWN
-240 189
-246 188
-248 183
-246 178
**********
# Draw a picture based on the txt file mystery
# When UP go to the next line, read x,y coordinates, go to that point
# When DOWN go to the next line, read x,y coordinates, go to that point and
continue until UP
import turtle
wn = turtle.Screen() # Set up the window and its attributes
wn.bgcolor("beige")
hadir = turtle.Turtle() # create hadir
hadir.color('orange')
hadir.speed(0)
datums = open("C:/Users/Roger/Documents/GitHub/LaunchCode/mystery.txt", "r")
for aline in datums:
splitted = aline.split()
try:
coords = [int(i) for i in splitted]
x = coords[0]
y = coords[1]
hadir.goto(x, y)
except:
while splitted == "UP":
hadir.pu()
while splitted == "DOWN":
hadir.pd()
turtle.exitonclick()
--
Roger Lea Scherer
623.255.7719
More information about the Tutor
mailing list