-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhangman_game_code.py
More file actions
39 lines (39 loc) · 1.26 KB
/
hangman_game_code.py
File metadata and controls
39 lines (39 loc) · 1.26 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
import random
from hangman_words import word_list
from hangman_art import stages, logo
lives = 6
print(logo)
chosen_word = random.choice(word_list)
print(chosen_word)
placeholder = ""
word_length = len(chosen_word)
for position in range(word_length):
placeholder += "_"
print("Word to guess: " + placeholder)
game_over = False
correct_letters = []
while not game_over:
print(f"************{lives}/6 LIVES LEFT*************")
guess = input("Guess a letter: ").lower()
if guess in correct_letters:
print(f"You've already guessed {guess}")
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("Word to guess: " + display)
if guess not in chosen_word:
lives -= 1
print(f"You guessed {guess}, that's not in the word. You lose a life.")
if lives == 0:
game_over = True
print(f"***************THE ACTUAL WORD IS {chosen_word}! YOU LOSE***************")
if "_" not in display:
game_over = True
print("************************YOU WIN************************")
print(stages[lives])