我已经测试了以下程序,并且没有错误。但每当我输入"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"
答案 0 :(得分:8)
这是因为您直接将与==
的元组进行比较,而False
总是会给raw_input
,因为tuple
会给出一个字符串,而不是in
{1}}。您需要检查序列中是否有任何一个响应。使用if response in ('Hangman', 'hangman'):
执行此操作:
elif
与{{1}}中的类似比较相同。