我在代码的输入部分有错误。通常情况下它运行良好但在此代码中,我不知道为什么会显示错误。
print("Welcome to the game, Hangman!")
print("I am thinking of a word that is ",len(secretWord)," letters long.")
print("-------------")
n=8
G_new=''
k=''
while n>0 and secretWord!=G_new:
print("You have ",n," guesses left.")
G_old=[G_new,]
print("Available letters: ",getAvailableLetters (G_old)
**k=input("Please guess a letter: ")** #error in this line
g=k.lower()
G_new=G_old+[g,]
if isWordGuessed(secretWord, G_new)==True and g not in G_old:
print("Good guess: ",getGuessedWord(secretWord, G_new))
elif isWordGuessed(secretWord, G_new)==True and g in G_old:
print("Oops! You've already guessed that letter: ",getGuessedWord(secretWord, G_old))
else:
print("Oops! That letter is not in my word: ",getGuessedWord(secretWord, G_old))
n-=1
print("-------------")
if n==0 and secretWord!=G_new:
print("Sorry, you ran out of guesses. The word was ",str(secretWord),".")
elif n>=0 and secretWord==G_new:
print("Congratulations, you won!")
答案 0 :(得分:0)
计算(
和)
:
print("Available letters: ",getAvailableLetters (G_old)
1 2 2 1????
作为一般规则,如果您收到语法错误,表示"意外"或者其他什么,错误总是永远不会出现在错误信息的行上 - 它实际上在某个地方更早,你输错了。指定的错误位置仅仅是解析器意识到存在问题的第一个地方。