On 10/2/2010 10:45 AM Steve Willoughby said...
On 02-Oct-10 10:32, Emile van Sebille wrote:

Well, not really -- this is the OPs code. I was responding to Joel's comment of not seeing the entire post.

File "my_turtle.py", line 19
if (abs(turtle.position()[0]) > turtle.window_height()/2) or
^
SyntaxError: invalid syntax

How does Python know that the next line is the continuation of your if
statement, instead of the beginning of a new line of code?

Because of the paren count -- I didn't actually parse the OPs code and so I assumed that, but now I'll assume the line break probably resulted post send.

Continuing-to-assume-ly y'rs,

Emile


Here's the code fragment now paren'd...

import turtle, random

def checkForward(distance):
        old_position = turtle.position()
        turtle._pen.up()
        # no show/hide turtle methods in my turtle module !
        turtle.forward(distance)
        forward_failed = outOfBounds()
        turtle.setx(old_position[0]); turtle.sety(old_position[1])
        turtle._pen.down()
        # no show/hide turtle methods in my turtle module !
        if outOfBounds() == 'false':
                turtle.forward(distance)

def stuck():
        return forward_failed

def outOfBounds():
        if ((abs(turtle.position()[0])>turtle.window_height()/2) or
(abs(turtle.position()[1])>  turtle.window_width()/2)):
                return "true"
        else:
                return "false"

def randomMove2(d1, d2, a1, a2):
         while 1:
                 turtle.left(random.uniform(a1,a2))
                 checkForward(random.uniform(d1,d2))
                 if outOfBounds() == 'true':
                         turtle.right(180)



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

Reply via email to