import random

class ch():
    def __init__(self, char, guessed):
        self.char = char
        self.guessed = guessed

file = 'words.txt'

with open(file, 'r') as f:
    data = f.readlines()

def r():
        word = random.choice(data)
        return word

def convert(word):
    word1 = []
    for s in word:
        word1.append(ch(s, 0))

    return word1


def isin(a, word):
    for s in word:
        if(a == s.char):
            for j in word:
                if a == j.char:
                    j.guessed = 1

            return True

    return False

lives = 6
w = r()
word = convert(w)
while lives > 0:
    for s in word:
        print (s.char, end = " ") if s.guessed == 1 else print ("_" , end = " ")

    a = input("your lives: " + str(lives) + ", please guess: ")
    if len(a) > 1:
        if(a == w):
            print("Congrats")
        else:
            print("yikes")
        break
            
    else:
        if not isin(a, word):
            lives -= 1

