Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import random
- class Hangman:
- def __init__(self):
- self.word_bank = []
- self.secret_word = ''
- self.already_guessed = []
- self.num_guesses = 0
- def __str__(self):
- pass
- def read_file(self):
- for line in open('wordbank.txt', 'r'):
- self.word_bank.append(line.strip())
- def get_random_word(self):
- self.secret_word = random.choice(self.word_bank)
- def print_word(self):
- print('Word to guess has {} letters'.format(len(self.secret_word)))
- def get_guess(self):
- try:
- guess = input('Guess a letter between A-Z: ')
- if guess.isnumeric():
- raise TypeError
- if guess == 'stop':
- return None
- self.already_guessed.append(guess)
- self.num_guesses += 1
- return True
- except TypeError:
- return False
- def num_guesses():
- pass
- def show_win():
- pass
- def main():
- game = Hangman()
- game.read_file()
- game.get_random_word()
- for i in range(1,50):
- print('')
- print('To stop playing type "stop".')
- print('')
- game.print_word()
- while game.get_guess() != None:
- if game.get_guess():
- game.get_guess()
- for i in range(1,50):
- print('')
- print('To stop playing type "stop".')
- print('')
- else:
- for i in range(1,50):
- print('')
- print('To stop playing type "stop".')
- print('')
- print('That is not a valid letter.')
- print('Thank you for playing.')
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement