-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathwordgame.py
More file actions
64 lines (47 loc) · 1.32 KB
/
wordgame.py
File metadata and controls
64 lines (47 loc) · 1.32 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
import random
def get_random_word():
words = ["pizza","cheese","apples"]
random_word = words[random.randint(0, len(words) - 1)]
return random_word
def show_word(word):
for character in word:
print(character, " ", end="")
print("")
def get_guess():
print("Enter a letter")
return input()
def process_letter(letter, secret_word, blanked_word):
result = False
for i in range(0, len(secret_word)):
if secret_word[i] == letter:
result = True
blanked_word[i] = letter
return result
def print_strikes(strikes):
for i in range(0, strikes):
print("X", end="")
print("")
def play_word_games():
strikes = 0
max_strikes = 3
playing = True
word = get_random_word()
blanked_word = list("_" * len(word))
while playing:
show_word(blanked_word)
letter = get_guess()
found = process_letter(letter, word, blanked_word)
if not found:
strikes += 1
print_strikes(strikes)
if strikes >= max_strikes:
playing = False
if not "_" in blanked_word:
playing = False
if strikes >= max_strikes:
print("Sorry. Game over.")
else:
print("Winner!")
print("Start the Game")
play_word_games()
print("End the Game")