-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathDay-7 Hangman Project.py
72 lines (44 loc) · 1.43 KB
/
Day-7 Hangman Project.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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
#import random to generate words from the list randomly
import random
from hangman_word_list import word_list
#Randomly choose a word from the word list and assign it to a variable called chosen_word
chosen_word = random.choice(word_list)
word_length = len(chosen_word)
end_of_game = 6
lives = 6
#import hangman logo
from hangman_art import logo
print(logo)
print(f'pssst, the solution is {chosen_word}')
#create an empty list called display
display = [ ]
#generate underscores(_) for the chosen_word using for loop
word_length = len(chosen_word)
for _ in range(word_length):
display += "_"
#print(display)
game_over = False
while game_over == False:
#user should guess a number
guess = input("Guess a letter:\n")
#convert the guess to a lowercase letter
guess = guess.lower()
if guess in display:
print(f"you have already guessed {guess}")
for placement in range(len(chosen_word)):
letter = chosen_word[placement]
if letter == guess:
display[placement] = letter
print(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:
end_of_game = True
print("You lose")
print(f"{' '.join(display)}")
if "_" not in display:
end_of_game = True
print("you win")
from hangman_art import stages
print(stages[lives])