Novice Issue

John Gordon gordon at panix.com
Thu Apr 18 10:21:36 EDT 2013


In <0fa050c1-3a00-4c17-9fa6-b79a22485c7a at googlegroups.com> Bradley Wright <bradley.wright.biz at gmail.com> writes:

> while raw_input != "quit" or "q":

Others have pointed out flaws in this statement.  However, even if you
had written the loop the 'correct' way:

    user_input = raw_input()
    while user_input != "quit" or user_input != "q":

There is still a logic bug.  This loop will execute forever, because no
matter what the user enters, it will be unequal to "q" or unequal to "quit".
Use 'and' instead of 'or'.

Of course in this specific situation, as others have suggested, 'in' is
better still.

-- 
John Gordon                   A is for Amy, who fell down the stairs
gordon at panix.com              B is for Basil, assaulted by bears
                                -- Edward Gorey, "The Gashlycrumb Tinies"




More information about the Python-list mailing list