-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHangman Game.py
More file actions
56 lines (42 loc) · 1.27 KB
/
Hangman Game.py
File metadata and controls
56 lines (42 loc) · 1.27 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
import random
words = ["apple", "movie", "alphabet", "superhero", "monkey", "perfume", "pirate", "powerful"]
main_word = random.choice(words)
guessed = []
lives = 0
max_lives = 6
hangman_stages = [
" O ",
" O \n | ",
" O \n /| ",
" O \n /|\\ ",
" O \n /|\\ \n / ",
" O \n /|\\ \n / \\ "
]
start = input("Press S to start the game: ").upper()
if start == "S":
while lives < max_lives:
hidden = ""
for letter in main_word:
if letter in guessed:
hidden += letter
else:
hidden += "-"
print(f"\nWord:{hidden}")
if hidden == main_word:
print("🎉 You won! The word was:", main_word)
break
ask = input("Guess a letter: ").lower()
if ask in guessed:
print("You already guessed that letter!")
continue
if ask in main_word:
guessed.append(ask)
print("✅ Correct guess!")
else:
lives += 1
print(f"❌ Wrong guess! Lives left:{max_lives - lives}")
print(hangman_stages[lives-1])
else:
print("💀 You lost! The word was:", main_word)
else:
print("Thank you, BYE!")