2015-09-27 91 views
0

当我猜这封信时,它一直在应用这封信。例如 所说的单词是单词,那么我会猜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)) 
+0

替换每个元素fake这是它给了我,当我改变假的猜测 –

+0

回溯(最近通话最后一个): print(''。join(guess))“E:\ Mike's CPT-135 python class \ hangManStudent \ hangManStudent \ src \ hangMan.py”,第44行, TypeError:序列项目0:期望的str实例,找到的列表 –

回答

0

这部分是罪魁祸首:

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)) 

此代码与guess

+0

这是当我更改假冒猜测时它给我的。 –

+0

回溯(最近通话最后一个): 文件 “E:\麦克的CPT-135 Python类\ hangManStudent \ hangManStudent的\ src \ hangMan.py”,第44行,在 打印 ( '' 加入(猜测)。) TypeError:序列项目0:期望的str实例,找到列表 –