[Tutor] while loop only executes once
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
> > 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
> 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