0

I'm trying to make a category select (by text interface) in Python 3, and I was wondering how I can compare if multiple strings are not true, and then print something along the lines of "that is not a valid choice"

    input("what is your category choice?")
    if categoryChoice != "category1", "category 2", "category 3":
    print("not a valid choice")

I don't understand the syntax for having it check if any of category1, category2, category3, etc is true/false

Karl Knechtel
  • 62,466
  • 11
  • 102
  • 153
user2353283
  • 11
  • 1
  • 3

1 Answers1

8

Use in for containment tests.

categoryChoice = input("what is your category choice?")
if categoryChoice not in ("category1", "category 2", "category 3"):
    print("not a valid choice")

http://ideone.com/e6n0Rr


By the way, if you're using Python 2, you should really use raw_input instead of input.

Matt Ball
  • 354,903
  • 100
  • 647
  • 710