我正在制作这个刽子手游戏的while循环问题。首先,它打印错误的答案,如5次,我不知道为什么?我试图得到它也让我猜另一个字母,但只有六个猜测或它的游戏结束。这是我到目前为止所做的。
import drawHangman
import turtle
def main():
#Do not change or remove code from herel
window = turtle.Screen()
window.setup(400, 400, 200, 200)
HG = turtle.Turtle()
drawHangman.default(HG)
#To here
main()
#Start your program below here You may still need other import
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)
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)
if guess == myword[re]: #If the guess is in the answer,
fake[re] = guess #change the fake to represent that, EACH TIME IT OCCURS
print(''.join(fake)) #converts from list to string
break
else:
print("Wrong guess!, guess again")
count =+ 1
while guess == ''.join(fake):
guess = input("Enter another letter you would like to guess: ")
if guess == myword[re]: #If the guess is in the answer,
fake[re] = guess #change the fake to represent that, EACH TIME IT OCCURS
print(''.join(fake)) #converts from list to string
main()