[Tutor] function error

Emile van Sebille emile at fenx.com
Sat Oct 2 20:42:16 CEST 2010

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,


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

import turtle, random

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

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"
                 return "false"

def randomMove2(d1, d2, a1, a2):
          while 1:
                  if outOfBounds() == 'true':

More information about the Tutor mailing list