Python Hangman Game Program Error

Discussion in 'Game programming' started by palak231, Apr 25, 2023.

  1. palak231

    palak231 New Member

    Joined:
    Sep 9, 2022
    Messages:
    18
    Likes Received:
    1
    Trophy Points:
    3
    Gender:
    Female
    Occupation:
    Software Developer
    Location:
    Haldwani, Uttarakhand
    Home Page:
    https://www.absmartly.com/
    Hello this is Gulshan Negi
    Well, I am writing a program for making a hangman game in Python but it shows some error at the time of its execution, I don't know what wrong I am doing here.

    Here is my source code:
    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):
     
        string=""
        count=0:
        s='abcdefghijklmnopqrstuvwxyz'
        for letter in s:
            if letter in guessed_letter_list:
                count+=1
            else:
                string+=letter
        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 ")
                print('\n'*50)
    
                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))
                    chances-=1
                else:
                    guessed_letter_list.append(guessInLowerCase)
                    print("NICE YOU GUSESSED THE RIGHT LETTER! ",guessed_word(word, guessed_letter_list))
              
            elif word==guessed_word(word, guessed_letter_list):
                print("YOU WON!")
                break
    
        else:
            print('''
            ********************************************
       YOU LOSS!!
                                     O
                                    /|\
                                    / \
         ******************************************''')
            print('The word was',word,)
    
    word = select_word()
    hangman_game(word)
    
    n above code I don't know what I am missing. Can anyone give their suggestions on this?
    Thanks
     
  2. shabbir

    shabbir Administrator Staff Member

    Joined:
    Jul 12, 2004
    Messages:
    15,376
    Likes Received:
    388
    Trophy Points:
    83
    You have to share the error details as well as what you are trying to do. Sharing the whole code and saying there is some error will not be enough for someone to help you out
     
  3. palak231

    palak231 New Member

    Joined:
    Sep 9, 2022
    Messages:
    18
    Likes Received:
    1
    Trophy Points:
    3
    Gender:
    Female
    Occupation:
    Software Developer
    Location:
    Haldwani, Uttarakhand
    Home Page:
    https://www.absmartly.com/
    Thanks a lot for your kind response, well error is showing in line no 9 and 21.
     
  4. palak231

    palak231 New Member

    Joined:
    Sep 9, 2022
    Messages:
    18
    Likes Received:
    1
    Trophy Points:
    3
    Gender:
    Female
    Occupation:
    Software Developer
    Location:
    Haldwani, Uttarakhand
    Home Page:
    https://www.absmartly.com/
    Well, there was same error with both count function i.e. count+=1: (Collon is not required here). Well I checked and took its reference from here.
    Thanks
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice