Hello.
I need some help with my code. It has to be in the format I am posting. So when I run the game, it is basically supposed to keep asking for a guess until the number of guess reach 0 or until the word is found. Number of guesses start at 4 and decrease every single time the player inputs a wrong guess. The program is supposed to recognize repeated guesses of the same letter as a wrong guess. If the player guesses a letter correctly, the corresponding _ in the blanks are replaced with the letter, even if there are multiple occurrences of that letter within the word. If the player guesses all letters correctly and number of guesses is greater than 0, then the player wins. I have posted my code below. I think the problem is in the update_puzzle_string() block as it is updating the "temp" variable to give me the blanks with the word filled in. Please review it and let me know what I am doing wrong. All help is appreciated
I need some help with my code. It has to be in the format I am posting. So when I run the game, it is basically supposed to keep asking for a guess until the number of guess reach 0 or until the word is found. Number of guesses start at 4 and decrease every single time the player inputs a wrong guess. The program is supposed to recognize repeated guesses of the same letter as a wrong guess. If the player guesses a letter correctly, the corresponding _ in the blanks are replaced with the letter, even if there are multiple occurrences of that letter within the word. If the player guesses all letters correctly and number of guesses is greater than 0, then the player wins. I have posted my code below. I think the problem is in the update_puzzle_string() block as it is updating the "temp" variable to give me the blanks with the word filled in. Please review it and let me know what I am doing wrong. All help is appreciated

import random def main(): # Display Instructions instruction_list = ['Keep guessing letters until your guesses run out'] x = 0 y = 0 instructions(instruction_list) #Display Puzzle String word = 'apple' blanks = (' _ '*len(word)) display_puzzle_string(blanks) #Play Game num_guess = 4 guess = '' guessed_letters = [] temp = '' 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: guess = get_guess(num_guess) update_puzzle_string(blanks, temp, word, correct_guess, guess, guessed_letters) guessed_letters += guess update_num_guess(correct_guess, num_guess) display_updated_puzzle(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(blanks, temp, word, correct_guess, guess, guessed_letters): for count, item in enumerate(word): if item == guess and item != guessed_letters: correct_guess = True temp += guess else: correct_guess = False temp += blanks[count] return temp def update_num_guess(correct_guess,num_guess): if correct_guess == True: num_guess = num_guess else: num_guess += 1 def display_updated_puzzle(temp): print('The answer so far is: ' + ''.join(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()
(Feb-12-2019, 07:17 PM)A1395 Wrote: this one is wrong. The temp gives an empty value. It does not update. The input letter does not seem to register with the program. What could be wrong?
Hello.
I need some help with my code. It has to be in the format I am posting. So when I run the game, it is basically supposed to keep asking for a guess until the number of guess reach 0 or until the word is found. Number of guesses start at 4 and decrease every single time the player inputs a wrong guess. The program is supposed to recognize repeated guesses of the same letter as a wrong guess. If the player guesses a letter correctly, the corresponding _ in the blanks are replaced with the letter, even if there are multiple occurrences of that letter within the word. If the player guesses all letters correctly and number of guesses is greater than 0, then the player wins. I have posted my code below. I think the problem is in the update_puzzle_string() block as it is updating the "temp" variable to give me the blanks with the word filled in. Please review it and let me know what I am doing wrong. All help is appreciated![]()
import random def main(): # Display Instructions instruction_list = ['Keep guessing letters until your guesses run out'] x = 0 y = 0 instructions(instruction_list) #Display Puzzle String word = 'apple' blanks = (' _ '*len(word)) display_puzzle_string(blanks) #Play Game num_guess = 4 guess = '' guessed_letters = [] temp = '' 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: guess = get_guess(num_guess) update_puzzle_string(blanks, temp, word, correct_guess, guess, guessed_letters) guessed_letters += guess update_num_guess(correct_guess, num_guess) display_updated_puzzle(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(blanks, temp, word, correct_guess, guess, guessed_letters): for count, item in enumerate(word): if item == guess and item != guessed_letters: correct_guess = True temp += guess else: correct_guess = False temp += blanks[count] return temp def update_num_guess(correct_guess,num_guess): if correct_guess == True: num_guess = num_guess else: num_guess += 1 def display_updated_puzzle(temp): print('The answer so far is: ' + ''.join(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()