Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/bin/env python3
- #
- from random import choice
- WORDS = tuple( frozenset( #open('words.txt')))
- #FIXME: stub
- ('qwe', 'rty', 'uio')))
- TRYOUTS = 5
- def get_words():
- while True:
- yield choice(WORDS)
- def yes(prompt):
- return input(prompt).startswith('y')
- def getchar(prompt=''):
- while True:
- c = input(prompt)
- if c: return c[0]
- def guess_char(word, prompt=''):
- return getchar(prompt) in word
- def guess_word(word, prompt=''):
- return word == input(prompt)
- def play_guess_game(word, tryouts):
- print('The word have {} characters. \n'
- 'instructions msg...'
- .format(len(word))
- )
- mk_prompt = 'You have {} chars left to try: '.format
- guesses = (
- guess_char(word, mk_prompt(t))
- for t in range(tryouts, 0, -1)
- )
- for correct in guesses:
- print('char is in!'
- if correct else
- 'char is out!'
- )
- print('No chars left instructions...')
- print('Win! msg.'
- if guess_word(word, 'Type the word: ') else
- 'loose msg'
- )
- def main():
- print('Welcome msg...')
- for word in get_words():
- play_guess_game(word, TRYOUTS)
- if not yes('Play again?'):
- break
- print('Goodbye msg...')
- if __name__ == '__main__':
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement