Advertisement
Guest User

Untitled

a guest
Apr 6th, 2020
205
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.69 KB | None | 0 0
  1. import random
  2.  
  3. class Hangman:
  4.  
  5.     def __init__(self):
  6.         self.word_bank = []
  7.         self.secret_word = ''
  8.         self.already_guessed = []
  9.         self.num_guesses = 0
  10.  
  11.     def __str__(self):
  12.         pass
  13.  
  14.     def read_file(self):        
  15.         for line in open('wordbank.txt', 'r'):
  16.             self.word_bank.append(line.strip())
  17.  
  18.     def get_random_word(self):
  19.         self.secret_word = random.choice(self.word_bank)
  20.  
  21.     def print_word(self):
  22.         print('Word to guess has {} letters'.format(len(self.secret_word)))
  23.  
  24.     def get_guess(self):
  25.         try:
  26.             guess = input('Guess a letter between A-Z: ')
  27.             if guess.isnumeric():
  28.                 raise TypeError
  29.             if guess == 'stop':
  30.                 return None
  31.             self.already_guessed.append(guess)
  32.             self.num_guesses += 1
  33.             return True
  34.         except TypeError:
  35.             return False
  36.  
  37.     def num_guesses():
  38.         pass
  39.  
  40.     def show_win():
  41.         pass
  42.  
  43. def main():
  44.     game = Hangman()
  45.     game.read_file()
  46.     game.get_random_word()
  47.     for i in range(1,50):
  48.         print('')
  49.     print('To stop playing type "stop".')
  50.     print('')
  51.     game.print_word()
  52.     while game.get_guess() != None:
  53.         if game.get_guess():
  54.             game.get_guess()
  55.             for i in range(1,50):
  56.                 print('')
  57.             print('To stop playing type "stop".')
  58.             print('')
  59.         else:
  60.             for i in range(1,50):
  61.                 print('')
  62.             print('To stop playing type "stop".')
  63.             print('')
  64.             print('That is not a valid letter.')
  65.     print('Thank you for playing.')
  66.  
  67. main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement