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 Matthew Richardson other posts by this author
Jun 30 2003 10:23PM messages near this date
Re: [Tutor] newbie 'while' question | Re: [Tutor] newbie 'while' question
On Mon, 2003-06-30 at 13:51, Kalle Svensson wrote:
>  -----BEGIN PGP SIGNED MESSAGE-----
>  Hash: SHA1
>  
>  [Matthew Richardson]
>  > s = raw_input('Enter a name: ')
>  > x = 0
>  > while x >= 0:
>  >     print s[x]
>  >     x += 1
>  > 
>  > The error is expected because the counter goes on beyond the number of
>  > characters in the string and runs out of stuff to print.  Got that part
>  > of it.  How can I count the number of characters in the string?  Then
>  > the while statement could be changed to
>  > 
>  > while x <= NumOfChar:
>  >     dosomestuff
>  
>  This is very close to the correct solution.  You get the number of
>  characters in the string with the len() built-in function.  But
>  
>    s = raw_input('Enter a name: ')
>    x = 0
>    while x <= len(s):
>        print s[x]
>        x += 1
>  
>  will still result in an IndexError (even though it's close to being
>  correct).  Do you see why?
>  
>  Peace,
>    Kalle
>  - -- 
>  Kalle Svensson, http://www.juckapan.org/~kalle/

Thanks to all of the guidance on solving a very basic problem.  It'll
probably take me some time to get into the proper mindset to work this
stuff out, so I appreciate the help and patience.

Matt

-- 
Matt Richardson
Instructional Support Technician
Department of Art
CSU San Bernardino



_______________________________________________
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