我已经测试了下面的程序,没有错误。但每当我输入"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"
最佳答案
这是因为您正直接与带有==
的元组进行比较,后者总是给出False
,因为raw_input
给出的是字符串,而不是tuple
。您需要检查序列中是否有任何响应。使用in
执行此操作:
if response in ('Hangman', 'hangman'):
与
elif
中的类似比较类似。