Skip to content

Instantly share code, notes, and snippets.

@dbowring
Last active December 22, 2015 04:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dbowring/6419866 to your computer and use it in GitHub Desktop.
Save dbowring/6419866 to your computer and use it in GitHub Desktop.
'''
Sample Output:
Solution: Python is Cool
______ __ ____
Next Guess: p
p_____ __ ____
Next Guess: o
p___o_ __ _oo_
Next Guess: t
p_t_o_ __ _oo_
Next Guess: h
p_tho_ __ _oo_
Next Guess: y
pytho_ __ _oo_
Next Guess: n
python __ _oo_
Next Guess: s
python _s _oo_
Next Guess: i
python is _oo_
Next Guess: c
python is coo_
Next Guess: l
Solved! Answer: Python is Cool
'''
import string
solution = raw_input('Solution: ').lower()
guessed = set()
required = set(s for s in solution if s in string.ascii_lowercase)
def mask_character(c):
if c in string.ascii_lowercase:
if not c in guessed:
return '_'
return c
while guessed ^ required:
print ''.join(mask_character(c) for c in solution)
char = raw_input('Next Guess: ').strip()
if char and char[0] in string.ascii_letters:
guessed.add(char[0].lower())
print 'Solved! Answer:', solution
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment