-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
51 lines (40 loc) · 1.26 KB
/
main.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
42
43
44
45
46
47
48
49
50
51
#Step 5
from replit import clear
import random
import hangman_art
import hangman_words
#TODO-1: - Update the word list to use the 'word_list' from hangman_words.py
chosen_word = random.choice(hangman_words.word_list)
lives = 6
spaces = "_"
guess_list = []
#TODO-3: - Import the logo from hangman_art.py and print it at the start of the game.
print(hangman_art.logo)
# #Testing code
# print(f'Pssst, the solution is {chosen_word}.')
#Create blanks
display = []
for _ in range(0, len(chosen_word)):
display += "_"
space = "_"
while space in display:
guess = input("Guess a letter: ").lower()
clear()
#Check guessed letter
for letter in range(0, len(chosen_word)):
if chosen_word[letter] == guess:
display[letter] = guess
print(display)
if guess not in chosen_word and guess not in guess_list:
lives -= 1
print(f"{guess} is not in the word; \n {hangman_art.stages[lives]}")
if guess in guess_list:
print("You guessed this letter already.")
if space not in display:
print(f"{' '.join(display)}")
print("You Win")
if lives == 0:
print(f"{' '.join(display)}")
print(f"You lose. The word was {chosen_word}")
space = "-"
guess_list.append(guess)