-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathhanged.py
More file actions
157 lines (130 loc) · 2.77 KB
/
Copy pathhanged.py
File metadata and controls
157 lines (130 loc) · 2.77 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
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
# -*- coding: utf-8 -*-
import random
IMAGES = ['''
+---+
| |
|
|
|
|
=========''', '''
+---+
| |
O |
|
|
|
=========''', '''
+---+
| |
O |
| |
|
|
=========''', '''
+---+
| |
O |
/| |
|
|
=========''', '''
+---+
| |
O |
/|\ |
|
|
=========''', '''
+---+
| |
O |
/|\ |
| |
|
=========''', '''
+---+
| |
O |
/|\ |
| |
/ |
=========''', '''
+---+
| |
O |
/|\ |
| |
/ \ |
=========''', '''
''']
WORDS = [
'machine',
'car',
'programmer',
'python',
'hello',
'world',
'computer',
'keyboard',
'music',
'byte',
'bit',
'debbuging',
'work',
'elephant',
'programming',
'issue',
'github'
]
def fill_all_letters(hidden_word, current_letter):
for index in range(len(current_letter)):
hidden_word[index] = current_letter[index]
def display_message(message):
print('')
print(message)
def random_word():
idx = random.randint(0, len(WORDS) - 1)
return WORDS[idx]
def display_board(hidden_word, tries):
print(IMAGES[tries])
print('')
print(hidden_word)
print('--- * --- * --- * --- * --- * --- ')
def run():
word = random_word()
hidden_word = ['-'] * len(word)
tries = 0
while True:
display_board(hidden_word, tries)
current_letter = str(input('Please introduce a charter or the complete word: '))
letter_indexes = []
if len( current_letter ) > 1:
if current_letter == word:
fill_all_letters(hidden_word, current_letter)
display_board(hidden_word, tries)
display_message('Congrats, you won!!. the word is: {}'.format(word))
break
else:
for idx in range(len(word)):
if word[idx] == current_letter:
letter_indexes.append(idx)
if len(letter_indexes) == 0:
tries += 1
if tries == 7:
display_board(hidden_word, tries)
display_message('Sorry! :( the correct word is: {}'.format(word))
break
else:
for idx in letter_indexes:
hidden_word[idx] = current_letter
letter_indexes = []
try:
hidden_word.index('-')
except ValueError:
display_board(hidden_word, tries)
display_message('Congrats, you won!!. the word is: {}'.format(word))
break
if __name__ == '__main__':
print('W E L C O M E')
run()