ASPN ActiveState Programmer Network
ActiveState
/ Home / Perl / PHP / Python / Tcl / XSLT /
/ Safari / My ASPN /
Cookbooks | Documentation | Mailing Lists | Modules | News Feeds | Products | User Groups


Recent Messages
List Archives
About the List
List Leaders
Subscription Options

View Subscriptions
Help

View by Topic
ActiveState
.NET Framework
Open Source
Perl
PHP
Python
Tcl
Web Services
XML & XSLT

View by Category
Database
General
SOAP
System Administration
Tools
User Interfaces
Web Programming
XML Programming


MyASPN >> Mail Archive >> python-Tutor
python-Tutor
Re: [Tutor] newbie 'while' question
by Danny Yoo other posts by this author
Jun 30 2003 10:43PM messages near this date
Re: [Tutor] newbie 'while' question | Re: [Tutor] newbie 'while' question
>  > In mathematical terms, we'd say that we'd like a half-open range,
>  >
>  >
>  >          0  <=  x   < length of "Matthew Ricahrdson"
>  >
>  >
>  > And we'll find that the equivalent expression in Python is very similar to
>  > this.  *grin*
>  >
>  >
>  > I hope this gives some hints on how to correct the while 'condition'
>  > expression.  Good luck!
> 
>  I knew I should have paid more attention in math...


You did have the right approach.  That is, you approached it from the
left:

    while x > = 0:                   #  0 <= x

You just had to have the right approach.  *grin*

    while x < len(s):               #  x < len(s)





By the way, it turns out that we can do both directions at the same time:

    while 0 <= x < len(s):          #  0 <= x and x < len(s)


which is a safe way to go about it.  Of course, only a few programmers I
know will ever write the condition like this.  *grin* Most will just
write:

    x < len(s)

and just assume that x is nonnegative.  Crazy programmers.  *grin*



Good luck to you!


_______________________________________________
Tutor maillist  -  Tutor@[...].org
http://mail.python.org/mailman/listinfo/tutor
Thread:
Matthew Richardson
Danny Yoo
Matthew Richardson
Kalle Svensson
Eric L Howard
Danny Yoo
Matthew Richardson
Matthew Richardson
Matthew Richardson
Danny Yoo
Matthew Richardson
Danny Yoo
Zak Arntson
Zak Arntson
Zak Arntson

Zak Arntson

Privacy Policy | Email Opt-out | Feedback | Syndication
© ActiveState Software Inc. All rights reserved