[Tutor] while loop only executes once

Andy W toodles@yifan.net
Wed, 19 Dec 2001 19:14:46 +0800


> Brett Kelly wrote:
> >
> > ok, here's my loop.  it only goes through once and exits.
> > (words is a dictionary with each letter of the alphabet corresponding to
a
> > different word)
> >
> > name = raw_input("Please enter your name: ")
> > name.lower()

Also here, this doesn't assign the lowered string to name.
Change it to

name=name.lower()

<snip/>

>
> I have a feeling that your troubles come from using two separated loops
> when one will do, or from not nesting your loops if you want them to
> interact with each other. A for loop is probably a better choice for the
> above output, along the lines of
>
> for letter in name:
>     print words[letter]
>
> (which is probably easier to understand than the double-indexed stuff in
> the while loop above).

I'd have to agree with that. Just remember that lower() bit, though! :)

>
> _______________________________________________
> Tutor maillist  -  Tutor@python.org
> http://mail.python.org/mailman/listinfo/tutor
>