import random def main(): num_guesses = 4 instruction_file=open('instructions.txt', 'r') list_of_words = ['apple', 'banana', 'watermelon', 'kiwi', 'pineapple', 'mango'] answer=random.choice(list_of_words) puzzle=['_'] * len(answer) def display_instructions(instruction_file): file_contents=instruction_file.read() instruction_file=instruction_file.close() print(file_contents) def get_guess(num_guesses): print('The number of guesses remaining is ' + str(num_guesses)+ '.') letter_input = input("Guess a letter ") return letter_input def update_puzzle_string(letter_input,puzzle,answer): if get_guess(num_guesses) in answer: for i,x in enumerate(answer): if x is get_guess: puzzle[i]=letter_input return True def display_puzzle_string(puzzle): print('The current state of the puzzle is '+str(puzzle)) def is_word_found(puzzle,answer): is_word_found=True puzzle_string=print(''.join(puzzle)) if puzzle_string == answer: return False def play_game(answer,puzzle): while True: display_puzzle_string(puzzle) get_guess(num_guesses) update_puzzle_string(get_guess,puzzle,answer) print(str(puzzle)) is_word_found(puzzle,answer) display_instructions(instruction_file) play_game(answer,puzzle) main()
Sorry for formatting issues. The goal of this program is to collect a guess from a user then compare it to a randomly selected word from a list after doing so it updates a puzzle that has blanks where the letter belongs, if all letters of the word are guessed, user is told they are correct. User gets 4 guesses. It is basically hangman. When I execute this program it just prints the instructions, the initial puzzle state, requests a guess then keeps asking for guesses. I don't understand why this isn't working. I'll implement the number of guesses after I get help with this.