0

Python 3 で (テキスト インターフェイスで) カテゴリを選択しようとしています。

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

カテゴリ 1、カテゴリ 2、カテゴリ 3 などのいずれかが true/false であるかどうかをチェックするための構文がわかりません

4

1 に答える 1

6

in封じ込め試験に使用します。

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


ちなみに、Python 2 を使用している場合は代わりraw_inputinput.

于 2013-05-06T03:48:51.533 に答える