所以我的一段代码最好在与字符列表比较后打印出不完整的单词。
例如,如果单词是 stackoverflow 并且列表包含's','a','k', 'o', 'r','l'
输出应该是
s _ a _ k o _ _ r _ l o _
我的代码是
def getGuessedWord(secretWord, lettersGuessed):
'''
secretWord: string, the word the user is guessing
lettersGuessed: list, what letters have been guessed so far
returns: string, comprised of letters and underscores that represents
what letters in secretWord have been guessed so far.
'''
i=0
gameWord=''
while i in range(len(secretWord)):
if(i%2!=0):
gameWord+=' ' #to print spaces between characters
else:
if(secretWord[i] in lettersGuessed):
gameWord+=secretWord[i]
else:
gameWord+='_'
return gameWord
但我的代码只是挂起!我不知道为什么!