-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhangman.py
53 lines (42 loc) · 1.48 KB
/
hangman.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
class Hangman:
def __init__(self, w):
self.word = w.upper()
self.correctLetters = []
self.already= []
self.boy = ['', '\n o', '\n/', '|', '\\', '\n /', '\\']
self.boyStr = ''
self.miss = 0
self.win = False
self.lost = False
consonants = 0
vowels = 0
i = 0
wordLenght = len(self.word)
while (i < wordLenght):
self.correctLetters.append('_')
for letter in self.word:
letter = self.word[i]
if (letter == 'A' or letter == 'E' or letter == 'I' or letter == 'O' or letter == 'U'):
vowels = vowels+1
else:
consonants = consonants+1
i+= 1
self.difficult = str(round(consonants/vowels*10, 2))
def attempt(self, guess):
guess = guess.upper()
if(guess in self.word and not(guess in self.already)):
self.already.append(guess)
i = 0
for letter in self.word:
if (guess == letter):
self.correctLetters[i] = letter
i+= 1
elif not(guess in self.already):
self.already.append(guess)
self.miss+= 1
self.boyStr = self.boyStr + self.boy[self.miss]
else:
self.miss+= 1
self.boyStr = self.boyStr + self.boy[self.miss]
self.lost = self.miss == 6
self.win = '_' not in self.correctLetters