import random

print("Welcome to hangman game")
print("_" * 25)
print("Hint: function in python!")

wordDictionary = ["print", "def" , "if" , "for" ,"import" , "elif", "else" , "while" , "true" ,"false" ,"len" ,"break" , "max" , "return", "input" ,"from" ,"finally", "or" ,"try" ,"with", "except","raise" , "pass" ,"as" ,"del" ,"lambda","continue" ,"not" ,"none", "nonlocal"]

randomWord = random.choice(wordDictionary)


def hangman_game():
    for x in randomWord:
        print("_", end="  ")


def print_hangman(wrong):
    if wrong == 1:
        print("\n+---+")
        print("---|")
        print("   |")
        print("   |")
        print("  ===")

    elif wrong == 2:
        print("\n+---+")
        print("O---|")
        print("    |")
        print("    |")
        print("   ===")
    elif wrong == 3:
        print("\n+---+")
        print("O---|")
        print("|   |")
        print("    |")
        print("   ===")
    elif wrong == 4:
        print("\n+---+")
        print(" O---|")
        print("/|   |")
        print("     |")
        print("    ===")
    elif wrong == 5:
        print("\n+---+")
        print(" O---|")
        print("/|\  |")
        print("     |")
        print("    ===")
    elif wrong == 6:
        print("\n+---+")
        print(" O---|")
        print("/|\  |")
        print("/    |")
        print("    ===")

    elif wrong == 7:
        print("\n+---+")
        print(" O---|")
        print("/|\  |")
        print("/ \  |")
        print("    ===")
        



def printWord(guessedLetters):
    counter = 0
    rightLetters = 0
    for char in randomWord:
        if char in guessedLetters:
            print(randomWord[counter], end="  ")
            rightLetters += 1
        else:
            print("  ", end="  ")
        counter += 1
    return rightLetters


def printLines():
    print("\r")
    for char in randomWord:
        print("\u203E", end="  ")


while True:
    length_of_word_to_guess = len(randomWord)
    amount_of_times_wrong = 0
    current_guess_index = 0
    current_letters_guessed = []
    current_letters_right = 0

    while amount_of_times_wrong != 7 and current_letters_right != length_of_word_to_guess:
        letterGuessed = input("\nGuess a letter: ").lower()

        print("\nLetters guessed so far:  ")
        for letter in current_letters_guessed:
            print(letter, end="  ")

        if randomWord[current_guess_index] == letterGuessed:
            print(amount_of_times_wrong)
            current_guess_index += 1
            current_letters_guessed.append(letterGuessed)
            current_letters_right = printWord(current_letters_guessed)
            printLines()

        else:
            amount_of_times_wrong += 1
            current_letters_guessed.append(letterGuessed)

            print_hangman(amount_of_times_wrong)

            current_letters_right = printWord(current_letters_guessed)
            printLines()
    if amount_of_times_wrong ==7 and printWord !=randomWord  :
         print("\nGame is over thank you for playing :) ","\nthe word was: ",randomWord )
         
    else :
        print  ("\nCongratulations , you did a good job!!") 
            
       

    restart = input("\nDo you want to play again? (yes/no): ")
    if restart.lower() !="yes" :
        break
        