Python 3:来自“用 Python 发明游戏”的编码刽子手。语法 msg 说“无效语法”并突出显示打印功能。我认为问题在于刽子手单词列表和拆分方法。谢谢你的帮助。
import random
HANGMANPICS = ['''
+---+
| |
|
|
|
|
|
=========''', '''
+---+
| |
O |
|
|
|
|
=========''', '''
+---+
| |
O |
| |
|
|
|
=========''', '''
+---+
| |
O |
/| |
|
|
|
=========''', '''
+---+
| |
O |
/|\ |
|
|
|
=========''', '''
+---+
| |
O |
/|\ |
/ |
|
|
=========''', '''
+---+
| |
O |
/|\ |
/ \ |
|
|
=========''']
words = '''ant baboon badger bat bear beaver camel cat clam
cobra cougar coyote crow deer dog donkey duck eagle ferret
fox frog goat gooose hawk lion lizard llama mole monkey
moose mouse mule newt otter owl panda parrot pigeon python
rabbit ram rat raven rhino salmon seal shark sheep skunk
sloth snake spider stork swan tiger toad trout turkey
turtle weasel whale wolf wombat zebra'''.split()
def getRandomWord (wordList):
wordIndex = random.randint(0, len(wordList) -1)
return wordList[wordIndex]
def displayBoard (HANGMANPICS, missedLetters, correctLetters, secretWord):
print(HANGMANPICS[len(missedLetters)]
print() #this print statement is highlighted w/invalid syntax msg
print('Missed letters:', end=' ')
for letter in missedLetters:
print(letter, end=' ')
print()
blanks = '_' * len(secretWord)
for i in range(len(secretWord)): #replaces blanks w/correctly guessed ltrs
if secretWord[i] in correctLetters:
blanks = blanks[:i] + secretWord[i] + blanks[i + 1:]
for letter in blanks: #show secret word w/spaces between ltrs
print(letter, end=' ')
print()