當我猜這封信時,它一直在應用這封信。例如 所說的單詞是單詞,那麼我會猜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實例,找到的列表 –