How do I set up a while loop to test for more than 1 variable

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • danl
    New Member
    • Oct 2009
    • 2

    How do I set up a while loop to test for more than 1 variable

    Code:
    errorType = raw_input("Please enter A or B or C as the Error Type: ")
    while errorType != "A":
            print "Not valid"               
            errorType = raw_input("Please enter a valid Error Type ")
    This works but I want the loop to check for != "B" and != "C" also.

    How do I set it up to do this as I am very new to Python.
    Last edited by bvdet; Oct 10 '09, 01:04 AM. Reason: Add code tags
  • bvdet
    Recognized Expert Specialist
    • Oct 2006
    • 2851

    #2
    Code:
    while True:
        errorType = raw_input("Please enter A or B or C as the Error Type: ")
        if errorType.upper() in ('A', 'B', 'C'):
            break
        else:
            print "Invalid entry. Valid responses are 'A', 'B', and 'C'"

    Comment

    • danl
      New Member
      • Oct 2009
      • 2

      #3
      Thank you, It is so obvious now.

      Comment

      Working...