-
Notifications
You must be signed in to change notification settings - Fork 0
/
hangman.py
41 lines (30 loc) · 977 Bytes
/
hangman.py
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
import random
from art import stages, logo
from vocab import word_list
print(logo)
game_is_finished = False
lives = len(stages) - 1
chosen_word = random.choice(word_list)
word_length = len(chosen_word)
display = []
for _ in range(word_length):
display += "_"
while not game_is_finished:
guess = input("Guess a letter: ").lower()
if guess in display:
print(f"You've already guessed {guess}")
for position in range(word_length):
letter = chosen_word[position]
if letter == guess:
display[position] = letter
print(f"{' '.join(display)}")
if guess not in chosen_word:
print(f"You guessed {guess}, that's not in the word. You lose a life.")
lives -= 1
if lives == 0:
game_is_finished = True
print("You lose.")
if not "_" in display:
game_is_finished = True
print("You win.")
print(stages[lives])