Last active
December 22, 2015 04:49
-
-
Save dbowring/6419866 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
''' | |
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