我开始编程了,我试着给"Hangman"编程.现在我想大部分的东西都是我自己做的,但这一件我还在苦苦挣扎. 我想保存多个索引,以便将"_"替换为所需的字符.
guess = ""
for x in randomWord:
guess = str(guess) + "_"
#Calculates the index for the found lette
for i in randomWord:
wordIndex = randomWord.find(userInput)
#If Statement deconstructs string into list and adds found letter
if wordIndex > -1:
guess = list(guess)
guess[wordIndex] = userInput
guess = "".join(guess)
missLett -= 1
我在某个地方读到,这个列举可以帮助我解决我的问题,但就是不能掌握它的诀窍.