-
-
Save rgregory1/50a476d53bcff8d42d451d11774bf0dc to your computer and use it in GitHub Desktop.
Simple Hang-Man Game for practice
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
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() | |
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
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