# Hangman Game using python

**URL:** <https://forum.codewithmosh.com/t/hangman-game-using-python/28592>\
**Category:** Python\
**Created:** [September 7, 2024, 7:21am UTC](https://forum.codewithmosh.com/t/hangman-game-using-python/28592 "2024-09-07T07:21:25Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![KdeltaX](https://avatars.discourse-cdn.com/v4/letter/k/3bc359/32.png) [@KdeltaX](https://forum.codewithmosh.com/u/KdeltaX)\
**Post date:** [September 7, 2024, 7:21am UTC](https://forum.codewithmosh.com/t/hangman-game-using-python/28592/1 "2024-09-07T07:21:25Z")

</div>

A fun project i did in my free time. Please do review it!!

---

<div class="post-metadata">

**Author:** ![kevinhu](https://avatars.discourse-cdn.com/v4/letter/k/ba9def/32.png) [@kevinhu](https://forum.codewithmosh.com/u/kevinhu)\
**Post date:** [September 10, 2024, 5:33pm UTC](https://forum.codewithmosh.com/t/hangman-game-using-python/28592/2 "2024-09-10T17:33:25Z")

</div>

Nice! I will wait to see that 😃

---

<div class="post-metadata">

**Author:** ![KdeltaX](https://avatars.discourse-cdn.com/v4/letter/k/3bc359/32.png) [@KdeltaX](https://forum.codewithmosh.com/u/KdeltaX)\
**Post date:** [September 12, 2024, 12:08pm UTC](https://forum.codewithmosh.com/t/hangman-game-using-python/28592/3 "2024-09-12T12:08:23Z")

</div>

word\_to\_guess=“”  
found\_letters=  
incorrect\_guess\_count=0  
hints=  
def hangman():  
def accept():  
global word\_to\_guess  
global hints  
word\_to\_guess = input(“Enter word for other team to guess!”).upper().strip()  
print(f"The word you entered is {word\_to\_guess.upper()}, right?")  
validate\_input = input(“Enter yes/no”).lower().strip()  
if validate\_input != ‘yes’:  
accept()  
print(“Enter 2 hints for other team”)  
print(“Hints will be displayed only if guess is incorrect”)  
hints = [input(“Enter 1st hint”), input(“Enter second hint”)]

```
def setter():
    global found_letters
    print("You have to guess a word")
    for i in range(len(word_to_guess)):
        found_letters.append("_ ")

def guess():
    global incorrect_guess_count
    if "_ " not in found_letters:
        print("U have guessed it correctly! congratulations!")
        print(f"The word was {word_to_guess}")
        return None

    print("Guesses so far: ")
    for i in range(len(found_letters)):
        print(found_letters[i], end=" ")
    print()
    next_guess = input("Guess next letter: ").upper()
    if not next_guess.isspace():
        next_guess = next_guess.strip()[0]
    if next_guess in word_to_guess:
        if word_to_guess.count(next_guess) > 1:
            for j in range(len(word_to_guess)):
                if word_to_guess[j] == next_guess:
                    found_letters[j] = next_guess
        else:
            found_letters[word_to_guess.index(next_guess)] = next_guess
    else:
        print(f"Incorrect Guess! You have {5 - incorrect_guess_count} incorrect guesses left!")
        print(f'''The hints are:
{hints[0]}
{hints[1]}''')
        incorrect_guess_count += 1
        if incorrect_guess_count > 5:
            print("You have failed to guess")
            print(f"The word was {word_to_guess}")
            return None

    guess()
accept()
setter()
guess()

```

hangman()  
while True:  
continue\_game = input(“Continue game to next round? (yes/no)”).lower().strip()  
if continue\_game != ‘yes’:  
break  
hangman()
