Feb-13-2019, 04:01 PM
import random def main(): # Display Instructions instruction_list = ['Keep guessing letters until your guesses run out'] instructions(instruction_list) #Display Puzzle String word = 'apple' blanks = ('_'*len(word)) display_puzzle_string(blanks) #Play Game num_guess = 4 guess = '' guessed_letters = [] temp = ('_'*len(word)) word_found = False correct_guess='' play_game(num_guess, guessed_letters, temp, word_found, blanks, word, correct_guess) #Display Result display_result(word_found, num_guess, word) #End Game end_game() def instructions(instruction_list): # Display Instructions for instruction in instruction_list: print(instruction) def display_puzzle_string(blanks): print('The answer so far is: '+ blanks) return blanks def play_game(num_guess, guessed_letters, temp, word_found, blanks, word, correct_guess): while num_guess>0 and word_found == False: correct_guess = False guess = get_guess(num_guess) new_temp, correct_guess = update_puzzle_string(temp, word, correct_guess, guess, guessed_letters) guessed_letters += guess num_guess = update_num_guess(correct_guess, num_guess) display_updated_puzzle(new_temp) is_word_found(temp) return word_found def get_guess(num_guess): guess = input('Guess a letter (You have ' + str(num_guess) + ' guesses remaining): ') return guess def update_puzzle_string(temp, word, correct_guess, guess, guessed_letters): new_temp = '' for count, item in enumerate(word): if item == guess and item not in guessed_letters: correct_guess = True new_temp += guess else: new_temp += temp[count] return new_temp, correct_guess def update_num_guess(correct_guess,num_guess): if correct_guess == True: num_guess = num_guess else: num_guess += -1 return num_guess def display_updated_puzzle(new_temp): print('The answer so far is: ' + ''.join(new_temp)) def is_word_found(temp): if '_' in temp: word_found = False else: word_found = True return word_found def display_result(word_found, num_guess, word): if word_found == True: print('Good job! You found the word' + word) elif num_guess==0: print('Not quite, the correct word was ' + word+'.Better luck next time') def end_game(): input('Press enter to end the game') main()New temp is being updated each turn but it is still being refreshed. Not elongated though. So I want to input a and get a____, then p and get app___. Right now I am getting a_____, and if I input p I get _pp___. What can I do to make the letters accumulate and completely replace all the blanks in the new_temp if all letters are guessed currently?