Python I';我正在为字谜游戏和can'编写代码;我不知道如何将一行文本包含到循环中

Python I';我正在为字谜游戏和can'编写代码;我不知道如何将一行文本包含到循环中,python,string,function,loops,methods,Python,String,Function,Loops,Methods,我正在为字谜游戏编写代码,并尝试在下面的输出图像中添加一行“到目前为止,答案是”之前的“____;” 显示说明 infile = open('wp_instructions.txt', 'r') line = infile.readline() while line: print(line.strip()) #prints line line = infile.readline() #loops the iteration

我正在为字谜游戏编写代码,并尝试在下面的输出图像中添加一行“到目前为止,答案是”之前的“____;”

显示说明

infile = open('wp_instructions.txt', 'r')
line = infile.readline()
while line:
    print(line.strip())                 #prints line
    line = infile.readline()            #loops the iteration
infile.close()    
words = ['apple', 'banana', 'watermelon', 'kiwi', 'pineapple', 'mango']
word = random.choice(words)

symbol = "_"                             
blanklines = len(word) * symbol
status = "The answer so far is "
print(status, end=" ") 

guesses = ''
这里可以使用任意圈数

turns = 4


while turns > 0:
统计用户失败的次数

failed = 0
输入的所有字符。 逐字逐句

对于word中的字符:

    # comparing that character with
    # the character in guesses
    if char in guesses: 
        print(char, end= ' ')

    else:
                  
        print("_", end= ' ')
        
        # for every failure 1 will be
        # incremented in failure
        failed += 1


if failed == 0:
    # user will win the game if failure is 0
    # and 'You Win' will be given as output
    print("Good job! You found the word", word + '!') 
    endgame_button = input('Press enter to end the game.')
    if endgame_button == '':        
        break

# if user has input the wrong alphabet then
# it will ask user to enter another alphabet
guess = input("\nGuess a letter (" + str(turns) + " " + "guesses remaining): ")

# every input character will be stored in guesses 
guesses += guess 

# check input with the character in word
if guess not in word:

    turns -= 1

    
    if turns == 0:
        print('Not quite, the correct word was ' + str(word)+ '. Better luck next time')
        endgame_button = input('Press enter to end the game.')
        if endgame_button == '':
                break

不清楚你需要什么。。尽量减少你的问题或更好地解释它(我的建议用简短的描述)@adirabargil我编辑了它,希望它现在有意义
    # comparing that character with
    # the character in guesses
    if char in guesses: 
        print(char, end= ' ')

    else:
                  
        print("_", end= ' ')
        
        # for every failure 1 will be
        # incremented in failure
        failed += 1


if failed == 0:
    # user will win the game if failure is 0
    # and 'You Win' will be given as output
    print("Good job! You found the word", word + '!') 
    endgame_button = input('Press enter to end the game.')
    if endgame_button == '':        
        break

# if user has input the wrong alphabet then
# it will ask user to enter another alphabet
guess = input("\nGuess a letter (" + str(turns) + " " + "guesses remaining): ")

# every input character will be stored in guesses 
guesses += guess 

# check input with the character in word
if guess not in word:

    turns -= 1

    
    if turns == 0:
        print('Not quite, the correct word was ' + str(word)+ '. Better luck next time')
        endgame_button = input('Press enter to end the game.')
        if endgame_button == '':
                break