[Tutor] Turtle drawing

2018-06-05 Thread Roger Lea Scherer
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
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Turtle drawing

2018-06-05 Thread Alan Gauld via Tutor
On 05/06/18 21:46, Roger Lea Scherer wrote:

> datums = open("C:/Users/Roger/Documents/GitHub/LaunchCode/mystery.txt", "r")
> 
> for aline in datums:
> splitted = aline.split()
> try:...
> except:
> while splitted == "UP":
> hadir.pu()

splitted will never equal 'UP' or 'DOWN' because the result
of split() is always a list - even if its empty. So I suspect
you are not actually executing any up/down operations.

Try using splitted[0] instead.

The other problem is that you use a while loop but never
change the condition values so, if it ever did pass the test,
you'd wind up with an infinite loop! You only need an if clause
not a while.

HTH
-- 
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/
http://www.amazon.com/author/alan_gauld
Follow my photo-blog on Flickr at:
http://www.flickr.com/photos/alangauldphotos


___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
https://mail.python.org/mailman/listinfo/tutor