Graphics=['''
------------
| |''','''
------------
| |
| O''','''
------------
| |
| O
| / ''','''
------------
| |
| O
| / |''','''
------------
| |
| O
| / |
| | ''','''
------------
| |
| O
| / |
| |
| /
|
| ''','''
------------
| |
| O
| / |
| |
| / |
|
| ''']
import random
class Hangman():
def Playing(self):
listOfWords = ["example", "says", "python", "rocks"]
again = True
while again:
guessWord = random.choice(listOfWords)
board = "*" * len(guessWord)
alreadySaid = set()
mistakes = 7
print(" ".join(board))
guessed = False
while not guessed and mistakes > 0:
whatplayersaid = input("Guess a letter: ")
if whatplayersaid in guessWord:
alreadySaid.add(whatplayersaid)
board = "".join([char if char in alreadySaid else "_" for char in guessWord])
if board == guessWord:
guessed = True
else:
mistakes -= 1
print("Nope.", mistakes, "mistakes left.")
print("Letters Guessed:",guessed)
print(Graphics[6-mistakes])
print(" ".join(board))
again = (input("Again [y/n]: ").lower() == 'y')
Hangman().Playing()
我希望保持猜测字母的进度,并在每次猜测时打印出来。我该怎么做?,我现在只返回最后一次不正确的猜测
答案 0 :(得分:1)
您需要做的是不打印print(Graph)
这会打印Graph数组的位置。您需要打印如下内容:
print(Graph[7-mistakes])