-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhangman.py
More file actions
64 lines (50 loc) · 1.74 KB
/
Copy pathhangman.py
File metadata and controls
64 lines (50 loc) · 1.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import random
from hangman_words import word_list
from hangman_art import stages, logo
# Game settings
lives = 6
game_over = False
correct_letters = []
# Display logo
print("\n" + "=" * 40)
print(logo)
print("=" * 40 + "\n")
# Randomly choose a word
chosen_word = random.choice(word_list)
word_length = len(chosen_word)
# Placeholder for the word
placeholder = "_" * word_length
print(f"\n🚀 Let's Play Hangman! 🚀\n")
print(f"🔍 Word to guess: {' '.join(placeholder)}\n")
while not game_over:
print(f"\n{'*' * 30} {lives}/6 ❤️ LIVES LEFT {'*' * 30}\n")
guess = input("🎯 Guess a letter: ").lower()
# Check if the letter was already guessed
if guess in correct_letters:
print(f"\n⚠️ You've already guessed '{guess}'. Try another letter! ⚠️\n")
continue
display = ""
for letter in chosen_word:
if letter == guess:
display += letter
correct_letters.append(guess)
elif letter in correct_letters:
display += letter
else:
display += "_"
print(f"\n🔍 Word to guess: {' '.join(display)}\n")
if guess not in chosen_word:
lives -= 1
print(f"\n❌ Oops! '{guess}' is not in the word. You lost a life. ❌\n")
print(stages[lives]) # Display hangman stage
if lives == 0:
game_over = True
print("\n" + "=" * 60)
print(f"💀 GAME OVER! The word was '{chosen_word.upper()}'. Better luck next time! 💀")
print("=" * 60 + "\n")
if "_" not in display:
game_over = True
print("\n" + "=" * 50)
print("🎉🎉 CONGRATULATIONS! YOU WIN! 🎉🎉")
print("=" * 50 + "\n")
print("🎮 Thanks for playing Hangman! 🎮\n")