[Tutor] A range of numbers

Leung Cris krazie_mu_boi at hotmail.com
Mon Dec 1 18:54:53 EST 2003


THX!


>From: Gregor Lingl <glingl at aon.at>
>To: Leung Cris <krazie_mu_boi at hotmail.com>
>CC: tutor at python.org
>Subject: Re: [Tutor] A range of numbers
>Date: Tue, 02 Dec 2003 00:53:35 +0100
>
>Hi Leung!
>
>There is a range function in Python:
>
> >>> range(5)
>[0, 1, 2, 3, 4]
> >>> range(5,10)
>[5, 6, 7, 8, 9]
>
>It outputs lists of integer values.
>play around with it to learn how it works.
>(Even to call range(10,20,2), i. e. with
>3 arguments, is possible)
>
>On the other han you can check if some value
>is in a certain range with the in - Operator:
>
> >>> y = 4
> >>> y in range(5)
>True # 1 in older Versions of Python
> >>> y in range(5,10)
>False # or 0
>
>so if you first extract the coordinates of
>your mouse-position:
>
> >>> x,y = mouse_position()
>
>then you can easily check if y is in the desired
>range.
>
>HTH
>Gregor
>
>
>
>Leung Cris schrieb:
>
> > I was wondering if it is possible to set a variable or something to a
> > RANGE of numbers. For instance , I want to have it so that when I
> > mouse clicks in a certain region( let say, from (100,100) to
> > (200,200)), it prints out "You Clicked!" . I'm doing this with
> > Livewires right now. Of course, it would take forever if i try to write:
> >
> > if mouse_position() == (100,100) or (100,101) or (100,102)
> > ..............................
> > and mouse_buttons()['left'] == 1:
> > do something
> >
> > that won't work... so , can anyone help?
> >
> > _________________________________________________________________
> > MSN ¬Ûï´£¨Ñ±z³Ì²³æªº¤è¦¡¤À¨É¨Ã¦C¦L±zªº¬Û¤ù¡A½Ð²¾¦Ü :
> > http://photos.msn.com.hk/support/worldwide.aspx
> >
> > _______________________________________________
> > Tutor maillist - Tutor at python.org
> > http://mail.python.org/mailman/listinfo/tutor
> >
> >
>

_________________________________________________________________
¨Ï¥Î MSN Messenger¡A»PªB¤Í¦b½u¤W²á¤Ñ: http://messenger.microsoft.com/tc 




More information about the Tutor mailing list