import random
hangman_art = [
"""
------
| |
|
|
|
|
---
""",
"""
------
| |
| O
|
|
|
---
""",
"""
------
| |
| O
| |
|
|
---
""",
"""
------
| |
| O
| /|
|
|
---
""",
"""
------
| |
| O
| /|\\
|
|
---
""",
"""
------
| |
| O
| /|\\
| /
|
---
""",
"""
------
| |
| O
| /|\\
| / \\
|
---
"""
]
def play_hangman():
print("🌟 Виселица 🌟")
forbidden_numbers = ['0', '1', '2', '3', '4', '5', '6', '7', '8', '9']
listOfWords = ["british", "suave", "integrity", "accent", "evil", "genius", "Downton"]
word = random.choice(listOfWords).lower()
guessed_letters = []
wrong_guesses = 0
max_wrong_guesses = 6
display_word = "_" * len(word)
while wrong_guesses < max_wrong_guesses and "_" in display_word:
print(hangman_art[wrong_guesses])
print(f"Слово: {display_word}")
print("Использованные буквы:", end=" ")
for letter in guessed_letters:
print(letter, end=" ")
print()
print(f"Осталось попыток: {max_wrong_guesses - wrong_guesses}")
guess = input("Выберите букву: ").lower()
if len(guess) != 1:
print("Пожалуйста, введите одну букву!")
continue
if guess in forbidden_numbers:
print("Пожалуйста, вводите только буквы, не цифры!")
continue
if guess in guessed_letters:
print("Вы уже выбирали эту букву!")
continue
guessed_letters.append(guess)
if guess in word:
print("Верно!")
new_display = []
for i in range(len(word)):
if word[i] == guess or display_word[i] != "_":
new_display.append(word[i])
else:
new_display.append("_")
display_word = "".join(new_display)
else:
print("Нет, её там нет.")
wrong_guesses += 1
if "_" not in display_word:
print(f"Поздравляем! Вы выиграли! Слово: {word}")
else:
print(hangman_art[wrong_guesses])
print(f"Вы проиграли! Загаданное слово было: {word}")
play_hangman()