-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpractice.py
More file actions
68 lines (49 loc) · 2.13 KB
/
practice.py
File metadata and controls
68 lines (49 loc) · 2.13 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
57
58
59
60
61
62
63
64
65
66
67
68
import random
import hangman_words
# TODO-1: - Update the word list to use the 'word_list' from hangman_words.py
word_list= hangman_words.word_list
lives = 6
# TODO-3: - Import the logo from hangman_art.py and print it at the start of the game.
import hangman_art
print(hangman_art.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:
# TODO-6: - Update the code below to tell the user how many lives they have left.
print(f"****************************{lives}/6 LIVES LEFT****************************")
guess = input("Guess a letter: ").lower()
# TODO-4: - If the user has entered a letter they've already guessed, print the letter and let them know.
if guess == guess:
print('you have already 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)
# TODO-5: - If the letter is not in the chosen_word, print out the letter and let them know it's not in the word.
# e.g. You guessed d, that's not in the word. You lose a life.
if guess not in chosen_word:
print(guess,'is not in the word.You loose a life')
lives -= 1
if lives == 0:
game_over = True
# TODO 7: - Update the print statement below to give the user the correct word they were trying to guess.
print(f"***********************IT WAS{chosen_word}! YOU LOOSE**********************")
if "_" not in display:
game_over = True
print("****************************YOU WIN****************************")
# TODO-2: - Update the code below to use the stages List from the file hangman_art.py
stages = hangman_art.stages
print(stages[lives])