Simple Hangman game in Python3 I made a simple Hangman game in Python:
import random 

class Hangman:

    def __init__(self):
        self.words = [&quot;bike&quot;, &quot;monkey&quot;, &quot;planet&quot;]
        self.random_word = random.choice(self.words)
        self.lenght = len(self.random_word)
        self.no_of_try = int(self.lenght) + 3
        self.empty_word = [&quot;_&quot;] * self.lenght

    @staticmethod
    def user_input():
        print(&quot;Enter a guess: &quot;)
        user_input = input()
        return user_input

    def find_index(self):
        letter = self.user_input()
        possition = self.random_word.index(letter)
        return (letter, possition)
    
    def substitue(self):
        try:
            guess_letter, guess_index = self.find_index()
            self.empty_word[guess_index] = guess_letter 
            print(self.empty_word)
            return True                     
        except ValueError as e:
            return False

    def play_game(self):
        while self.no_of_try &gt; 0:
            print(&quot;no: &quot; + str(self.no_of_try))
            game = self.substitue()
            if game:
                print(&quot;Bravo&quot;)
                self.no_of_try -=  1
            else:
                self.no_of_try -=  1
                print(&quot;Wrong&quot;)

            if &quot;_&quot; not in self.empty_word:
                print(&quot;You win&quot;)
                break
            if self.no_of_try == 0:
                print(&quot;Game over&quot;)
                break

if __name__ == &quot;__main__&quot;:
    h = Hangman()
    h.play_game()
Right now the program will have a problem if you use a word which has the same letter more than once. string.index will only return the index of the first occurrence. What you could do instead is use a set to check what letters still need to be guessed. If a character in the word is still in the set, it hasn’t been guessed and an underscore should be printed. If it isn’t in the set, it has been guessed and it should be printed.
The code can be simplified significantly. You only really need one function which takes a list of strings as an argument. You could do something like this:
import random

def hangman(word_list):
    word = random.choice(word_list)
    letters = set(word)
    guesses = len(word) + 3
    while len(letters) &gt; 0 and guesses &gt; 0:
        guess = input(str(guesses) + &quot; guesses left\nguess something:\n&quot;)
        if guess in letters:
            print(&quot;correct&quot;)
            letters.remove(guess)
        else:
            print(&quot;wrong&quot;)
        guesses -= 1
        print(*(ch if ch not in letters else '_' for ch in word))
    print(&quot;win&quot; if len(letters) == 0 else &quot;lose&quot;)

if __name__ == &quot;__main__&quot;:
    hangman([&quot;bike&quot;, &quot;monkey&quot;, &quot;planet&quot;, &quot;mississippi&quot;])

NITPICKING
You have a function in your current code which could be replaced with a call to input. the user_input function could be replaced with this: input(&quot;Enter a guess:\n&quot;). Also you can simplify this:
if game:
    print(&quot;Bravo&quot;)
    self.no_of_try -=  1
else:
    self.no_of_try -=  1
    print(&quot;Wrong&quot;)

into this:
self.no_of_try -=  1
print(&quot;Bravo&quot; if game else &quot;Wrong&quot;)

I also noticed a couple things in the __init__ method. The word list and the randomly chosen word’s length don’t need to be instance variables because they’re only used in __init__, and you don’t need to cast the length to int because it’s already an int.