[Tutor] function error

Emile van Sebille emile at fenx.com
Sat Oct 2 19:32:21 CEST 2010


On 10/2/2010 10:16 AM Joel Goldstick said...
>> ##############################################################################
>> 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)
>> #############################################################################
>
> I copied your code between the hash lines and get this:
>
>    File "my_turtle.py", line 19
>      if (abs(turtle.position()[0])>  turtle.window_height()/2) or
>                                                                 ^
> SyntaxError: invalid syntax
>
>
> Is that all of your code?  it seems to be cut off


Do you see it now?  Your reply contained the 10 ten lines or so of code 
that follows.

Emile



More information about the Tutor mailing list