我正在尝试为我的 Hangman 游戏概念在同一行打印文本。它更早地工作了,虽然在从大多数错误中修复了游戏之后,我似乎无法让它工作。用于打印的代码是:
def printWord():
guessedWords = []
guessedWordsCorrect = []
selectedWord = 'dog'
printWordLength = 0
printWordIndex = 0
printWord = ''
while printWordLength < len(selectedWord):
if selectedWord[printWordIndex] == " ":
print(" ",end='')
printWordLength = printWordLength + 1
printWordIndex = printWordIndex + 1
else:
if selectedWord[printWordIndex] in guessedWords:
print(selectedWord[printWordIndex],"",end='')
printWordLength = printWordLength + 1
printWordIndex = printWordIndex + 1
else:
print("_ ",end='')
printWordLength = printWordLength + 1
printWordIndex = printWordIndex + 1
print("")
我曾经end=""
尝试在同一行打印,以前效果很好,但这次没有运气?
运行代码时,除了将它们打印在同一行之外,一切正常。