-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgallows_game.py
120 lines (98 loc) · 1.68 KB
/
gallows_game.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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# Simple Gallows Game
import random
gallows = ("""
____
| |
|
|
|
|
____________""", """
____
| |
| o
|
|
|
____________
""", """
____
| |
| o
| /
|
|
_____________
""", """
____
| |
| o
| /|
|
|
_____________
""", """
____
| |
| o
| /|
|
|
_____________
""", """
____
| |
| o
| /|\\
| /
|
_____________
""", """
____
| |
| o
| /|\\
| / \\
|
____________
""")
words_list = ["pineapple", "pear", "banana", "grape", "kiwi", "lemon", "orange", "watermelon", 'lime']
# game
random_word = random.choice(words_list)
print(f'Your word to guess has: {len(random_word)} letters')
print()
for letter in random_word:
print('_ ', end='')
print('')
word_to_guess = len(random_word) * '_'
guess = []
mistakes = 0
while True:
if mistakes > 6:
print("You lost!")
break
if set(guess) == set(random_word):
print("You won!")
break
typed_letter = input("Enter the letter: ")
if typed_letter.isdigit():
print("You must enter the letter!")
elif len(typed_letter) > 1:
print("Error! Please enter one letter")
else:
if typed_letter in random_word:
guess.append(typed_letter)
if typed_letter in random_word:
a = ''
for i in range(len(random_word)):
if typed_letter == random_word[i]:
a += typed_letter
else:
a += word_to_guess[i]
word_to_guess = a
for i in range(len(word_to_guess)):
print(word_to_guess[i], ' ', end='')
print('')
else:
print(gallows[mistakes])
mistakes += 1