Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # hangman.py -- written to be all strategically solved as also difficult
- import random
- import os
- wordlist='''
- abruptly
- abyss
- acre
- adapt
- aerosol
- ahem
- album
- among
- arch
- avenue
- awkward
- bagpipes
- bamboo
- banjo
- bank
- beekeeper
- bench
- bikini
- bingo
- black
- blitz
- blizzard
- blue
- bluff
- blur
- boggle
- book
- bookworm
- brag
- buoyant
- boxcar
- brick
- brief
- brutal
- buffalo
- built
- bulk
- busy
- buzz
- buzzword
- calm
- camp
- candy
- cargo
- catch
- cash
- champ
- chalk
- charm
- cheap
- check
- cheeky
- chef
- chew
- chief
- chip
- chirp
- chop
- civil
- claw
- clap
- clip
- cloud
- clock
- club
- coax
- coin
- combo
- comic
- cook
- cough
- copy
- cube
- cuffs
- cyan
- climax
- climb
- cobweb
- comb
- comfy
- cozy
- crazy
- crawl
- crowd
- croquet
- crypt
- cubic
- curfew
- cycle
- cynical
- daily
- dazzle
- debt
- diary
- diva
- dizzy
- donor
- dojo
- dove
- dozen
- drill
- drop
- dump
- dunk
- duplex
- echo
- edgy
- eject
- embezzle
- employ
- empty
- encrypt
- enjoy
- envy
- epic
- equal
- etch
- ethnic
- evoke
- evolve
- exam
- excel
- exit
- feud
- fifty
- film
- fish
- fishhook
- fishy
- fizz
- flake
- flex
- flow
- fluid
- foam
- foil
- fork
- foxy
- fuel
- funny
- fridge
- from
- fuchsia
- funny
- galaxy
- galvanize
- gazebo
- gecko
- giant
- gigs
- girl
- gizmo
- glyph
- gossip
- groggy
- gulp
- guru
- gypsy
- gyro
- haiku
- haphazard
- havoc
- hawk
- hazy
- hertz
- hike
- hips
- hoax
- hook
- hoop
- howl
- hugs
- hunch
- hurry
- hype
- hyphen
- icebox
- icon
- idol
- igloo
- inch
- index
- info
- injury
- input
- irony
- itch
- ivory
- jackpot
- jazzy
- jelly
- jerk
- jigsaw
- jinx
- jiujitsu
- jobs
- jogs
- jockey
- jogging
- join
- joke
- jokingly
- joyful
- judge
- juicy
- jukebox
- jumbo
- jump
- junk
- jury
- kayak
- keep
- kegs
- ketchup
- keyhole
- khaki
- kick
- kilobyte
- kiosk
- kiwi
- klutz
- knapsack
- knock
- know
- koala
- lamp
- laugh
- lava
- left
- lilac
- limo
- loaf
- logic
- look
- loud
- love
- lucid
- lucky
- lust
- luxury
- lymph
- lyrics
- marquis
- matrix
- maze
- megahertz
- memo
- menu
- meow
- microwave
- milk
- mimic
- mini
- minx
- mnemonic
- mystify
- myth
- navy
- next
- nosy
- nuke
- numb
- nightclub
- obey
- object
- okay
- once
- only
- onyx
- ostrich
- ouch
- oval
- oven
- oxygen
- palm
- park
- pawn
- pajama
- peekaboo
- picnic
- pink
- pixel
- pizza
- ploy
- plug
- plump
- pneumonia
- poem
- poetic
- polkadot
- prez
- proud
- psyche
- psycho
- punch
- puppy
- puzzle
- python
- quack
- quartet
- quartz
- quench
- queue
- quick
- quilt
- quiz
- ramp
- rhubarb
- rhyme
- rhythm
- rickshaw
- risk
- scratch
- script
- shrink
- size
- skip
- slip
- slow
- snazzy
- soak
- sofa
- sphinx
- spritz
- spun
- squawk
- stop
- strength
- stretch
- subway
- subject
- swim
- swivel
- syndrome
- system
- symptom
- taco
- taxi
- thumbscrew
- topaz
- tour
- transplant
- trip
- twelfth
- twin
- type
- typical
- typhoon
- typo
- unhitch
- unknown
- unworthy
- uncle
- unzip
- uptown
- vacancy
- vacuum
- vaporize
- venue
- verb
- vibe
- vinyl
- violet
- vivid
- vixen
- vodka
- voice
- volt
- volume
- voodoo
- vortex
- wagon
- walk
- walkway
- waltz
- wave
- wavy
- waxy
- wheezy
- whiskey
- whip
- whomever
- wimpy
- wink
- witchcraft
- wizard
- woah
- woke
- wolf
- woozy
- work
- world
- worldwide
- wrap
- wristwatch
- xylophone
- yacht
- yawn
- yellow
- yelp
- yippee
- yoga
- young
- youthful
- yummy
- zephyr
- zero
- zigzag
- zilch
- zinc
- zipper
- zodiac
- zombie
- zoom
- '''.split('\n')[1:-1]
- random.shuffle(wordlist)
- tempwordlist=wordlist[:]
- HANGMANPICS = [r'''
- ._____.
- | \|
- |
- |
- |
- |
- /|\
- =============''', r'''
- ._____.
- | \|
- O |
- |
- |
- |
- /|\
- =============''', r'''
- ._____.
- | \|
- O |
- | |
- |
- |
- /|\
- =============''', r'''
- ._____.
- | \|
- O |
- |\ |
- |
- |
- /|\
- =============''', r'''
- ._____.
- | \|
- O |
- /|\ |
- |
- |
- /|\
- =============''', r'''
- ._____.
- | \|
- O |
- /|\ |
- \ |
- |
- /|\
- =============''', r'''
- ._____.
- | \| GAME
- O | OVER
- /|\ | ----
- / \ |
- |
- /|\
- =============''']
- def cls():
- os.system('cls' if os.name == 'nt' else 'clear')
- print
- def getRandomWord(x):
- if not x:
- x=wordlist[:]
- return tempwordlist.pop()
- def displayBoard(missedLetters, correctLetters, secretWord):
- cls()
- print ' H A N G M A N\n'
- print HANGMANPICS[len(missedLetters)]
- print ' Missed letters [' + missedLetters + ']\n',
- blanks = ''
- for i in range(len(secretWord)):
- if secretWord[i] in correctLetters:
- blanks += secretWord[i]
- else:
- blanks += '_'
- print " Mystery Word:",
- for letter in blanks:
- print letter,
- def getGuess(alreadyGuessed):
- while True:
- guess = raw_input('\n Guess a letter >>> ').strip()
- guess = guess.lower()
- if len(guess) != 1:
- print ' Single letter only please... %s' % secretWord
- elif guess in alreadyGuessed:
- print ' Already guessed that one, choose again...'
- elif guess not in 'abcdefghijklmnopqrstuvwxyz':
- print ' Please enter a LETTER'
- else:
- return guess
- def playAgain():
- print ' Again? Y/N'
- return raw_input('> ').strip().lower().startswith('y')
- missedLetters = ''
- correctLetters = ''
- secretWord = getRandomWord(tempwordlist)
- gameIsDone = False
- while True:
- displayBoard(missedLetters, correctLetters, secretWord)
- guess = getGuess(missedLetters + correctLetters)
- if guess in secretWord:
- correctLetters = correctLetters + guess
- foundAllLetters = True
- for i in range(len(secretWord)):
- if secretWord[i] not in correctLetters:
- foundAllLetters = False
- break
- if foundAllLetters:
- displayBoard(missedLetters, correctLetters, secretWord)
- print '\n\n Congratulations... you found the secret word!'
- gameIsDone = True
- else:
- missedLetters = missedLetters + guess
- if len(missedLetters) == len(HANGMANPICS) - 1:
- displayBoard(missedLetters, correctLetters, secretWord)
- print '\n\n You have run out of guesses\n The word was %s' % (secretWord)
- gameIsDone = True
- if gameIsDone:
- if playAgain():
- missedLetters = ''
- correctLetters = ''
- gameIsDone = False
- secretWord = getRandomWord(tempwordlist)
- else:
- break
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement