2015-09-27 85 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實例,找到列表 –