Skip to content

Instantly share code, notes, and snippets.

@Echocage
Created September 6, 2014 01:21
Show Gist options
  • Save Echocage/a84e710ed101eaad59a2 to your computer and use it in GitHub Desktop.
Save Echocage/a84e710ed101eaad59a2 to your computer and use it in GitHub Desktop.
import random
import urllib2
stages = [["O"], ["O", "|"], [" O", "/|"], [" O", "/|\\"], [" O", " /|\\", " /"], [" O", "/|\\", "/ \\"]]
words = urllib2.urlopen('http://pastebin.com/raw.php?i=1nCnmv2y').readlines()
words = map(lambda x: x.strip(), words)
words.sort(key=lambda x: len(x))
def display_stage(stage):
for piece in stage:
print piece
def display_word():
for letter in word:
print letter if letter in guesses else '_',
def solved():
return not filter(lambda x: x not in guesses, word)
stage_number = 0
difficulty = int(raw_input("Enter difficulty (%s-%s): " % (len(words[0]), len(words[-1]))))
word = random.choice(filter(lambda x: len(x) == difficulty, words))
guesses = []
while stage_number < 6:
guess = raw_input("Guess: ")
if guess not in guesses:
guesses += guess
if guess not in word:
stage_number += 1
display_stage(stages[stage_number - 1])
else:
display_word()
if solved():
break
else:
print 'You already tried that letter'
if stage_number == 6:
print 'Sorry you lost, the word was', word
else:
print 'Good job, you won!'
raw_input()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment