< Back to forum

Python Hangman Game Program Error

Hello this is Gulshan Negi Well, I am writing a program for making Hangman Game in Python but it shows some error at the time of its execution.

Here is my source code: import random def select_word(): words_in_computer_memory = ['magazine','stars','computer','python','organisation'] word = random.choice(words_in_computer_memory) return word def is_gussed(word, guessed_letter_list): count=0 for letters in word: if letters in guessed_letter_list: count+=1 if count==len(word): return True else: return False def guessed_word(word, guessed_letter_list): string="" for key in word: if key in guessed_letter_list: string+=key else: string+="_ " return string def available_letters(guessed_letter_list):

for letter in s:
    if letter in guessed_letter_list:
return string

def hangman_game(word):
length=len(word) print('''------------------WELCOME TO HANGMAN GAME--------------------------- O
/ \
''') print("The word you have to guess is of ",length, "letters long.") chances=2*len(word) i=0 guessed_letter_list=[] while (chances!=0):

    if word!=guessed_word(word, guessed_letter_list):
        print("You Got", chances, "Chances.")
        print("Letters you can enter should be from these ",available_letters(guessed_letter_list))
        guess=input("ENTER A LETTER ")

        guessInLowerCase = guess[0].lower()      
        if guessInLowerCase  in guessed_letter_list:
            print("SORRY! YOU HAVE GUSSED THIS LETTER ALREADY! ",guessed_word(word, guessed_letter_list))
        elif guessInLowerCase not in word: 
            print(" SORRY! THE LETTER IS NOT IN WORD",guessed_word(word, guessed_letter_list))
            print("NICE YOU GUSESSED THE RIGHT LETTER! ",guessed_word(word, guessed_letter_list))

    elif word==guessed_word(word, guessed_letter_list):
        print("YOU WON!")


YOU LOSS!! O /|\
/ \
* ** _ ** _ ** * ** _ ** _** ''') print('The word was',word,)

word = select_word() hangman_game(word)

Can anyone give their suggestions on this. Thanks

Asked by: gulshan212 on June 27, 2023, 12:50 p.m. Last updated on June 27, 2023, 12:51 p.m.

Enter your answer details below:

Enter your comment details below:

0 Answer(s)

Instruction to write good question
  1. 1. Write a title that summarizes the specific problem
  2. 2. Pretend you're talking to a busy colleague
  3. 3. Spelling, grammar and punctuation are important!

Bad: C# Math Confusion
Good: Why does using float instead of int give me different results when all of my inputs are integers?
Bad: [php] session doubt
Good: How can I redirect users to different pages based on session data in PHP?
Bad: android if else problems
Good: Why does str == "value" evaluate to false when str is set to "value"?

Refer to Stack Overflow guide on asking a good question.