[Tutor] A range of numbers
Alfred Milgrom
fredm at smartypantsco.com
Tue Dec 2 02:14:07 EST 2003
Hi Leung:
It's better to use "reply to all" in future, so your comments get posted to
the list as well, rather than just to the one person.
(I am copying this answer to the list now as well.)
Looking at your code, I am not sure what you think the end_mouse() code
will do, but there is a logic mistake.
Look at these lines:
> if 200 <= x <= 300 and 200 <= y <= 300 and
> mouse_buttons()['left'] == 1:
> break
> end_mouse()
> end_mouse()
Translation:
If the left button has been pressed inside the box:
break <=== This means 'break out of the while loop'.
No further code in the "while 1" loop will be executed, including
end_mouse()
(continuing with the code):
On the other hand, if the mouse is not in the box or if the mouse button
has not been pressed
end_mouse() <=== Ignore all further mouse presses.
So let's see what happens if that the program gets started:
Immediately the "if" test will fail (because you can't press the
cursor fast enough)
All further mouse presses get ignored
But you are still in the "while 1" infinite loop!
Hope this helps,
Fred Milgrom
At 09:53 PM 1/12/03 -0800, you wrote:
>I think i got the try ... except concept, but did i do something wrong
>here? cuz it freezes when i try this function
>
>_________
>def func():
> begin_graphics()
> box(200,200,300,300)
> while 1:
> begin_mouse()
> try:
> x,y = mouse_position()
> except:
> x,y = 0,0
> if 200 <= x <= 300 and 200 <= y <= 300 and
> mouse_buttons()['left'] == 1:
> break
> end_mouse()
> end_mouse()
> box(300,200,500,500)
>________________
>
More information about the Tutor
mailing list