当我猜这封信时,它一直在应用这封信。例如 所说的单词是单词,那么我会猜d的字母,那么它会做 ddddd。它使用该字母表示整个单词。这是我的代码。Python hang子手游戏循环
import random
print(" Welcome to the HangMan game!!\n","You will have six guesses to get the answer correct, or you will loose!!!",)
lines = open("../WordsForGames.txt").read()
line = lines[0:]
#lines 24-28 Randomly generate a word from a text file
words = line.split()
myword = random.choice(words)
print(myword)
words = myword
fake = '_'*len(myword)
count = 0
print(fake)
guesses = 0
guess = input("Enter a letter you would like to guess: ")
fake = list(fake) #This will convert fake to a list, so that we can access and change it.
for re in range(0, len(myword)):#For statement to loop over the answer (not really over the answer, but the numerical index of the answer)
fake[re] = guess #change the fake to represent that, EACH TIME IT OCCURS
print(''.join(fake))
if guess != (''.join(fake)):
print("The letter ", guess,"was in the word. Guess another letter please!")
guess = input("Enter another letter you would like to guess: ")
fake[re] = guess #change the fake to represent that, EACH TIME IT OCCURS
print(''.join(fake))
替换每个元素
fake
这是它给了我,当我改变假的猜测 –回溯(最近通话最后一个): print(''。join(guess))“E:\ Mike's CPT-135 python class \ hangManStudent \ hangManStudent \ src \ hangMan.py”,第44行, TypeError:序列项目0:期望的str实例,找到的列表 –