[Tutor] While loop issue, variable not equal to var or var
Joseph Lee
joseph.lee22590 at gmail.com
Sat Jul 12 09:15:22 CEST 2014
Hi Steve,
In your conditionals:
…
while message != 'q' or 'Q'/message != “q” or message != “Q”:
…
Python will only match the first variable. A better approach (which might be a good solution) would be capturing the exit commands in a list like this:
JL’s code:
while message not in [“q”, “Q”]:
# blah, blah, your code…
# code end
Effectively, we’re testing if the command is a member of our exit commands list, and if it is, we’ll fall off the loop. Try this solution and see if it works for you.
Cheers,
Joseph
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20140712/4a556847/attachment.html>
More information about the Tutor
mailing list