Python 2.7:如果代码块不起作用

The*_*tor 2 python if-statement python-2.7

我测试了以下程序,没有错误.但每当我输入"hangman"它时,都不会启动if名为的新语句代码块"if response_2".为什么不运行它?

    response_2 = raw_input("What would you like to play? Hangman or Word Guess?")
    if response_2 == ("Hangman", "hangman"):
        print "Running Hangman..."
        print "Catching Criminals..."
        print "Building Gallows..."
        print "Getting that one song boy from Pirate's of the Carribean"
    elif response_2 == ("Word_Guess", "word_guess", "word guess", "Word Guess", "Word guess", "word Guess", "Word_guess", "word_Guess"):
        print "Not completed yet"
Run Code Online (Sandbox Code Playgroud)

Ale*_*ton 8

这是因为你直接比较与元组==,这将永远给Falseraw_input给了一个字符串,而不是一个tuple.您需要检查序列中是否有任何一个响应.这样做in:

if response in ('Hangman', 'hangman'):
Run Code Online (Sandbox Code Playgroud)

同样在内部进行类似的比较elif.