Originally Posted by
Shield
Dang dude! You're amazing! I never thought about using list comprehension...
Thanks for this!
Here's a simple version of hangman i made if it helps at all.
python Code:
class Word:
def __init__(self, word):
self.word = word
self.hidden_word = []
self.guesses = []
self.limbs = 6
def setup(self):
self.letters = list(self.word)
self.hidden_word = list("_" * int(len(self.word)))
def guess(self, guess):
w1 = "".join(self.hidden_word)
for i in range(0, len(self.letters)):
if guess == self.letters[i]:
self.hidden_word[i] = self.letters[i]
print(''.join(self.hidden_word))
w2 = "".join(self.hidden_word)
if w1 == w2:
return False
else:
self.guesses.append(guess)
return True
def hang(self, man):
if man is False:
self.limbs -= 1
class Hangman(Word):
def play(self):
self.setup()
attempts = 0
while ''.join(self.hidden_word) != self.word and self.limbs>0:
print('Your Guesses:' + ", ".join(self.guesses))
print('Limbs left: ' + str(self.limbs))
self.hang(self.guess(input('Guess?')))
hangman = Hangman('burbon')
hangman.play()
it'd be cool to add something that goes to a site and grabs its word of the day and also a definition of the word or something you could use as a hint.