# Nested Loop Mini Project — Hangman
# while + for + for — two players, one word, letter by letter

# ─────────────────────────────────────────────
# Setup
# ─────────────────────────────────────────────

word = input("Player 1 — enter a word: ").lower()
print("\n" * 50)    # clear the screen

guessed = ""
max_attempts = 6
wrong = 0

# ─────────────────────────────────────────────
# Game loop
# ─────────────────────────────────────────────

while wrong < max_attempts:
    display = ""
    for letter in word:
        if letter in guessed:
            display += letter + " "
        else:
            display += "_ "

    print(f"Word: {display}")
    print(f"Wrong attempts: {wrong}/{max_attempts}")
    print(f"Guessed: {guessed}")

    if "_" not in display:
        print("Player 2 wins!")
        break

    guess = input("Guess a letter: ").lower()

    if guess in guessed:
        print("Already guessed.")
        continue

    guessed += guess

    found = False
    for letter in word:
        if letter == guess:
            found = True
            break

    if not found:
        wrong += 1
        print(f"Wrong! {max_attempts - wrong} attempts left.")
else:
    print(f"Player 2 loses. The word was '{word}'.")

# ─────────────────────────────────────────────
# What's really happening
# ─────────────────────────────────────────────

# while — keeps the game alive
# first for — builds the display, checks guessed letters
# second for — checks if new guess is in the word
# continue — skips duplicate guesses
# while...else — handles the loss when attempts run out

# ─────────────────────────────────────────────
# Go further
# ─────────────────────────────────────────────

# Add ASCII hangman that grows with each wrong guess
# Allow guessing the full word — not just one letter
# Add a round counter — best of 3
