Trying To Catch Invalid User Input

Victor Subervi victorsubervi at gmail.com
Sun Aug 23 17:04:57 CEST 2009


Hi;
I have the following:

style = raw_input('What style is this? (1 = short, 2 = long): ')
flag = 0
while flag == 0:
  if (style != 1) or (style != 2):
    style = raw_input('There was a mistake. What style is this? (1 = short,
2 = long): ')
  else:
    flag = 1

I would think this would catch errors and permit valid values, but it
doesn't. If I enter an erroneous value the first time, and the second time a
good value, it doesn't break the loop. Why?
TIA,
Victor
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20090823/eb7955cb/attachment.html>


More information about the Python-list mailing list