class Hangman():
def __init__(self):
print
"Welcome to 'Hangman', are you ready to die?"
print
"(1)Yes, for I am already dead.\n(2)No, get me outta here!"
user_choice_1 = raw_input("->")
在这一行我收到错误我是否需要为这个原始输入导入一些库
if user_choice_1 == '1':
print
"Loading nooses, murderers, rapists, thiefs, lunatics..."
self.start_game()
elif user_choice_1 == '2':
print
"Bye bye now..."
exit()
else:
print
"I'm sorry, I'm hard of hearing, could you repeat that?"
self.__init__()
答案 0 :(得分:1)
File "E:/PycharmProjects/untitled1/hangman.py", line 49 if guess in the_word and not in letters_used: ^ SyntaxError: invalid syntax Process finished with exit code 1
此错误表示问题不在于您的raw_input
行,而在于第49行的代码。[something] and not in [something]
不是有效的表达式。 not in
是一个二元运算符,因此需要两个参数,一个在两边。你只给了右边一个。尝试:
if guess in the_word and guess not in letters_used: