+ 1

whats wrong with this hangman?

when i play the game it works well (almost well). the game is putting some letters that i didnt even guess yet in the word that i need to complete. it seems right - to hekp the player and give him a hint about y=the word (because it puts like 3 chars in). but it helps too much and i dont know how to fix it. how can i fix it? (in order for you to see run the game by yourself). code: import random words = ["banana" , "apple" , "hangman"] #list of optional words that could be picked for the game. random_word = random.choice(words) #picking a random word from the list in order to play the game. random_word_copy = random_word #making a copy of the word in order to display it well later on. random_word_copy_list = list(random_word) #list of all the chars in the random word - it will be used in the while loop to make certain chars hidden. letters_guessed = [] #list that will be filled with chars that have been guessed. print("\t\t Hangman:\n") print('\t\t' + '_ ' * len(random_word) + '\n') tries = 6 while (tries > 0): tries -= 1 get_input = input("Enter Char: ") print("(tries: {})".format(tries)) if get_input not in letters_guessed: letters_guessed.append(get_input) for i in random_word: if i not in letters_guessed: random_word_copy_list[random_word.index(i)] = '_' if get_input in random_word and get_input in letters_guessed: random_word_copy_list[random_word.index(get_input)] = get_input print(' '.join(random_word_copy_list)) if '_' not in random_word_copy_list: print("Well Done! The Word was:" , random_word_copy) exit() print("You are out of tries")

25th Sep 2020, 10:14 PM
Yahel
Yahel - avatar
2 ответов
+ 5
Can you post the code link instead of copy pasting the whole code here
25th Sep 2020, 10:26 PM
Namit Jain
Namit Jain - avatar
+ 5
Anyways, I modified your code a bit to give the expected output! See if this is what you wanted (by the way, there was no need of so many variables) https://code.sololearn.com/cSpCeN0Pkbss/?ref=app
25th Sep 2020, 10:39 PM
Namit Jain
Namit Jain - avatar