learning from 100 Days of Code: The Complete Python Pro Bootcamp for 2022
import random
from replit import clear
from hangman_art import logo , stages
from hangman_words import word_list
print(logo)
chosen_word = random.choice(word_list)
word_length = len(chosen_word)
already_guessed = []
lives = 6
display = []
for _ in range(word_length):
display += "_"
while "_" in display and lives != 0:
guess = input("Guess a letter: ").lower()
clear()
if guess in already_guessed:
print(f"You've already guessed {guess}.")
elif guess not in chosen_word:
print(f"You guess {guess}, that's not in the word. You lose a life.")
lives -= 1
for position in range(word_length):
letter = chosen_word[position]
if letter == guess:
display[position] = letter
already_guessed += guess
print(stages[lives])
print(f"{' '.join(display)}")
if "_" not in display:
print("\nYou win!")
if lives == 0:
print("\nYou lose!")