[Tutor] function error
Joel Goldstick
joel.goldstick at gmail.com
Sat Oct 2 19:16:13 CEST 2010
On Sat, Oct 2, 2010 at 12:43 PM, roberto <roberto03 at gmail.com> wrote:
> On Thu, Sep 30, 2010 at 1:45 PM, ALAN GAULD <alan.gauld at btinternet.com> wrote:
>> Copy the code into a text file with a name ending in .py - lets call it
>> myfile.py for now
>> (if you have not already done so)
>>
>> From a bash prompt type
>>
>> $ python myfile.py
>>
>> Then cut n paste any error messages into an email to the list
>
> well, actually i corrected the code so that the function outOfBounds()
> is directly called (as you can see hereafter);
> but if you have time to run the code you'll see the same strange
> behavior as me (maybe):
> when the arrow hits anyone of the window borders, it gets stuck back
> and forth indefinitely and never starts the path again
>
> thank you in advance
> ##############################################################################
> 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
--
Joel Goldstick
More information about the Tutor
mailing list