-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnineLives.py
More file actions
60 lines (48 loc) · 1.53 KB
/
nineLives.py
File metadata and controls
60 lines (48 loc) · 1.53 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
import random
lives = 9
words = ['pizza', 'family', 'teeth', 'otter', 'train', 'plane', 'earth', 'light', 'brush']
secret_word = random.choice(words)
clue = list('??????') # store the clue
heart_symbol = u'\u2764' # show the lives left
guessed_word_correctly = False
# The variable is set as False to begin with because the player doesn't know the word when the game starts
def update_clue(guessed_letter, secret_word, clue, unknown_letters):
index = 0
while index < len(secret_word):
if guessed_letter == secret_word[index]:
clue[index] = guessed_letter
unknown_letters = unknown_letters - 1
index = index + 1
return unknown_letters
difficulty = input('Choose difficulty (type 1, 2 or 3):\n 1 Easy\n 2 Normal\n 3 Hard\n')
difficulty = int(difficulty)
if difficulty == 1:
lives = 12
elif difficulty == 2:
lives = 9
else:
lives = 6
clue = []
index = []
while index < len(secret_word):
clue.append('?')
index = index + 1
while lives > 0:
print(clue)
print('Lives left: ' + heart_symbol * lives)
guess = input('Guess a letter or the whole word: ')
if guess == secret_word:
guessed_word_correctly = True
break
if guess in secret_word:
unknown_letters = update_clue(guess, secret_word, clue, unknown_letters)
else:
print('Incorrect. You lose a life')
lives = lives - 1
if unknown_letters == 0:
guessed_word_correctly = True
break
#if guessed_word_correctly:
#print('You won! The secret word was ' + secret_word)
#else:
#print('You lost! The secret word was ' + secret_word)