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

0

1 Answer 1

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.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.