Advertisement
Guest User

Untitled

a guest
Mar 15th, 2015
262
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.35 KB | None | 0 0
  1. #!/bin/env python3
  2. #
  3.  
  4. from random import choice
  5.  
  6. WORDS = tuple( frozenset( #open('words.txt')))
  7. #FIXME: stub
  8.              ('qwe', 'rty', 'uio')))
  9. TRYOUTS = 5
  10.  
  11. def get_words():
  12.     while True:
  13.         yield choice(WORDS)
  14.  
  15. def yes(prompt):
  16.     return input(prompt).startswith('y')
  17.  
  18. def getchar(prompt=''):
  19.     while True:
  20.         c = input(prompt)
  21.         if c: return c[0]
  22.  
  23. def guess_char(word, prompt=''):
  24.     return getchar(prompt) in word
  25.  
  26. def guess_word(word, prompt=''):
  27.     return word == input(prompt)
  28.  
  29. def play_guess_game(word, tryouts):
  30.     print('The word have {} characters. \n'
  31.           'instructions msg...'
  32.           .format(len(word))
  33.     )
  34.  
  35.     mk_prompt = 'You have {} chars left to try: '.format
  36.     guesses = (
  37.         guess_char(word, mk_prompt(t))
  38.         for t in range(tryouts, 0, -1)
  39.     )
  40.     for correct in guesses:
  41.         print('char is in!'
  42.               if correct else
  43.               'char is out!'
  44.         )
  45.  
  46.     print('No chars left instructions...')
  47.     print('Win! msg.'
  48.           if guess_word(word, 'Type the word: ') else
  49.           'loose msg'
  50.     )
  51.  
  52. def main():
  53.     print('Welcome msg...')
  54.  
  55.     for word in get_words():
  56.         play_guess_game(word, TRYOUTS)
  57.  
  58.         if not yes('Play again?'):
  59.             break
  60.  
  61.     print('Goodbye msg...')
  62.  
  63. if __name__ == '__main__':
  64.     main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement