Re: [Tutor] newbie 'while' question
by Zak Arntson other posts by this author
Jun 30 2003 7:15PM messages near this date
Re: [Tutor] newbie 'while' question
|
Re: [Tutor] newbie 'while' question
> Hi,
>
> while x <= NumOfChar:
> dosomestuff
>
> Or maybe I'm off track here, too.
Well, yes and no. It depends on whether x <= NumOfChar will ever be false,
and break you out of the while loop. Two things to remember about while
loops:
a) They're dangerous, and
b) You (almost) always want an "escape route." In your case, definitely so.
Instead of considering integers, try modifying the string itself. I don't
want to give the answer away, so I'll try to get you started with a
different example:
> >> s = ''
> >> while s:
print 'yup'
Notice how you don't see 'yup' printed? That's because '' (an empty
string) is just as good as false. Did you see my prior post, about
accessing part of a string?
> >> s = 'frog'
> >> s[0]
'f'
> >> s[2:]
'og'
> >> s[6:]
''
There's a few hints towards my solution (which, admittedly, may not be the
best).
---
Zak Arntson
www.harlekin-maus.com - Games - Lots of 'em
_______________________________________________
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
|