Skip to content

Instantly share code, notes, and snippets.

@Ryoliveira
Created December 12, 2017 04:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save Ryoliveira/e5d88c981f225394d7ae6bdbd2a22f37 to your computer and use it in GitHub Desktop.
Save Ryoliveira/e5d88c981f225394d7ae6bdbd2a22f37 to your computer and use it in GitHub Desktop.
Simple Hang-Man Game for practice
import random
def welcome():
print("Welcome to HangMan!\n"
"You will have to guess my secret word!\n"
"If you fail 5 attempts, you will be hung!\n")
def secretWord():
with open("hangmanWords.txt", "r") as file:
wordList = [line.rstrip() for line in file]
selectedWord = random.choice(wordList)
hiddenWord = ["-" for i in range(len(selectedWord))]
return selectedWord, hiddenWord
def checkGuess(guess, word, letterList):
found = False
for i, letter in enumerate(word):
if guess == letter:
letterList[i] = guess
found = True
if not found : print("Incorrect Guess\n")
return letterList, found
def hangMan():
chances = 5
lettersGuessed = []
word, letterList = secretWord()
while chances > 0:
hiddenWord = ""
hiddenWord = hiddenWord.join(letterList)
print("\n" + hiddenWord)
if word == hiddenWord:
print("You win!\nCongratulations, you guess the secret word: {}".format(word.title()))
break
print("You have {} chances left". format(chances))
try:
guess = input("Guess a letter: ")
if not guess.isalpha() or len(guess) > 1 : raise ValueError
if guess in lettersGuessed:
print("That letter has already been guessed\n")
continue
else:
lettersGuessed.append(guess)
except ValueError:
print("Invalid Guess, Enter one letter from A-Z\n")
continue
letterList, correct = checkGuess(guess, word, letterList)
if not correct:
chances -= 1
if chances == 0:
print("Sorry, you didn't guess my secret word.\n"
"The word was: {}".format(word.title()))
def main():
welcome()
hangMan()
main()
abruptly
absurd
abyss
affix
askew
avenue
awkward
axiom
azure
bagpipes
bandwagon
banjo
bayou
beekeeper
bikini
blitz
blizzard
boggle
bookworm
boxcar
boxful
buckaroo
buffalo
buffoon
buxom
buzzard
buzzing
buzzwords
caliph
cobweb
cockiness
croquet
crypt
curacao
cycle
daiquiri
dirndl
disavow
dizzying
duplex
dwarves
embezzle
equip
espionage
euouae
exodus
faking
fishhook
fixable
fjord
flapjack
flopping
fluffiness
flyby
foxglove
frazzled
frizzled
fuchsia
funny
gabby
galaxy
galvanize
gazebo
giaour
gizmo
glowworm
glyph
gnarly
gnostic
gossip
grogginess
haiku
haphazard
hyphen
iatrogenic
icebox
injury
ivory
ivy
jackpot
jaundice
jawbreaker
jaywalk
jazziest
jazzy
jelly
jigsaw
jinx
jiujitsu
jockey
jogging
joking
jovial
joyful
juicy
jukebox
jumbo
kayak
kazoo
keyhole
khaki
kilobyte
kiosk
kitsch
kiwifruit
klutz
knapsack
larynx
lengths
lucky
luxury
lymph
marquis
matrix
megahertz
microwave
mnemonic
mystify
naphtha
nightclub
nowadays
numbskull
nymph
onyx
ovary
oxidize
oxygen
pajama
peekaboo
phlegm
pixel
pizazz
pneumonia
polka
pshaw
psyche
puppy
puzzling
quartz
queue
quips
quixotic
quiz
quizzes
quorum
razzmatazz
rhubarb
rhythm
rickshaw
schnapps
scratch
shiv
snazzy
sphinx
spritz
squawk
staff
strength
strengths
stretch
stronghold
stymied
subway
swivel
syndrome
thriftless
thumbscrew
topaz
transcript
transgress
transplant
triphthong
twelfth
twelfths
unknown
unworthy
unzip
uptown
vaporize
vixen
vodka
voodoo
vortex
voyeurism
walkway
waltz
wave
wavy
waxy
wellspring
wheezy
whiskey
whizzing
whomever
wimpy
witchcraft
wizard
woozy
wristwatch
wyvern
xylophone
yachtsman
yippee
yoked
youthful
yummy
zephyr
zigzag
zigzagging
zilch
zipper
zodiac
zombie
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment