Skip to content
This repository was archived by the owner on May 25, 2022. It is now read-only.

Added a word guessing game programmed in Python #488

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions projects/Word_Guessing_Game/word_guessing_game.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import random

with open("D:\Projects\PythonProjects\python_mini_projects\hangman_puzzle\words.txt", 'r') as f:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

provide relative path of words.txt otherwise exception will generate for file not found

data = f.read()

words = set(data.split("\n"))

print("\n\n\n\n\t\t\t********** WORD GUESSING GAME **********\n")
print("\t\t\tYou have 10 guesses to fill the following blanks to make a meaningful word.\n")

while True:
hangman = random.choice(list(words))
attempts = 10
lst = ['_']*len(hangman)
used = []
print("\t\t\t" + " ".join(lst) + '\n')
while attempts != 0:
inp = input("\t\t\tGuess a letter: ")
if inp.isalpha() and len(inp) == 1:
if inp in used:
print("\t\t\tYou have already tried this letter!\n")
continue
if inp in hangman:
for i in range(len(hangman)):
if hangman[i] == inp:
lst[i] = inp
print("\t\t\t" + " ".join(lst) + '\n')
used.append(inp)
if "_" not in lst:
break
else:
attempts -= 1
print("\t\t\tWrong!")
print(f"\t\t\tAttempts remaining: {attempts}")
print("\t\t\t" + " ".join(lst) + '\n')
used.append(inp)
else:
print("\t\t\tYou can enter only a single letter!\n")

if "".join(lst) == hangman:
print("\t\t\tCongrats, you did it!!")
else:
print("\t\t\tSorry! Better luck next time!")
print(f"\t\t\tThe word is '{hangman}'")

print(f"\t\t\tYou took {10-attempts} out of 10 attempts.\n")

more = input("\t\t\tWanna play more?(y/n): ")
if more == 'y':
print()
continue
elif more == 'n':
print("\t\t\tThanks for playing!\n")
break
213 changes: 213 additions & 0 deletions projects/Word_Guessing_Game/words.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,213 @@
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