Skip to content

Commit 0bad98a

Browse files
Merge pull request #1 from ahana-mukherjee/add-hangman-game
Add files via upload
2 parents 090e215 + 6b09f67 commit 0bad98a

File tree

3 files changed

+341
-0
lines changed

3 files changed

+341
-0
lines changed

Python/hangman_art.py

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
stages = ['''
2+
+---+
3+
| |
4+
O |
5+
/|\ |
6+
/ \ |
7+
|
8+
=========
9+
''', '''
10+
+---+
11+
| |
12+
O |
13+
/|\ |
14+
/ |
15+
|
16+
=========
17+
''', '''
18+
+---+
19+
| |
20+
O |
21+
/|\ |
22+
|
23+
|
24+
=========
25+
''', '''
26+
+---+
27+
| |
28+
O |
29+
/| |
30+
|
31+
|
32+
=========''', '''
33+
+---+
34+
| |
35+
O |
36+
| |
37+
|
38+
|
39+
=========
40+
''', '''
41+
+---+
42+
| |
43+
O |
44+
|
45+
|
46+
|
47+
=========
48+
''', '''
49+
+---+
50+
| |
51+
|
52+
|
53+
|
54+
|
55+
=========
56+
''']
57+
58+
logo = '''
59+
_
60+
| |
61+
| |__ __ _ _ __ __ _ _ __ ___ __ _ _ __
62+
| '_ \ / _` | '_ \ / _` | '_ ` _ \ / _` | '_ \
63+
| | | | (_| | | | | (_| | | | | | | (_| | | | |
64+
|_| |_|\__,_|_| |_|\__, |_| |_| |_|\__,_|_| |_|
65+
__/ |
66+
|___/ '''

Python/hangman_words.py

Lines changed: 215 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,215 @@
1+
word_list = [
2+
'abruptly',
3+
'absurd',
4+
'abyss',
5+
'affix',
6+
'askew',
7+
'avenue',
8+
'awkward',
9+
'axiom',
10+
'azure',
11+
'bagpipes',
12+
'bandwagon',
13+
'banjo',
14+
'bayou',
15+
'beekeeper',
16+
'bikini',
17+
'blitz',
18+
'blizzard',
19+
'boggle',
20+
'bookworm',
21+
'boxcar',
22+
'boxful',
23+
'buckaroo',
24+
'buffalo',
25+
'buffoon',
26+
'buxom',
27+
'buzzard',
28+
'buzzing',
29+
'buzzwords',
30+
'caliph',
31+
'cobweb',
32+
'cockiness',
33+
'croquet',
34+
'crypt',
35+
'curacao',
36+
'cycle',
37+
'daiquiri',
38+
'dirndl',
39+
'disavow',
40+
'dizzying',
41+
'duplex',
42+
'dwarves',
43+
'embezzle',
44+
'equip',
45+
'espionage',
46+
'euouae',
47+
'exodus',
48+
'faking',
49+
'fishhook',
50+
'fixable',
51+
'fjord',
52+
'flapjack',
53+
'flopping',
54+
'fluffiness',
55+
'flyby',
56+
'foxglove',
57+
'frazzled',
58+
'frizzled',
59+
'fuchsia',
60+
'funny',
61+
'gabby',
62+
'galaxy',
63+
'galvanize',
64+
'gazebo',
65+
'giaour',
66+
'gizmo',
67+
'glowworm',
68+
'glyph',
69+
'gnarly',
70+
'gnostic',
71+
'gossip',
72+
'grogginess',
73+
'haiku',
74+
'haphazard',
75+
'hyphen',
76+
'iatrogenic',
77+
'icebox',
78+
'injury',
79+
'ivory',
80+
'ivy',
81+
'jackpot',
82+
'jaundice',
83+
'jawbreaker',
84+
'jaywalk',
85+
'jazziest',
86+
'jazzy',
87+
'jelly',
88+
'jigsaw',
89+
'jinx',
90+
'jiujitsu',
91+
'jockey',
92+
'jogging',
93+
'joking',
94+
'jovial',
95+
'joyful',
96+
'juicy',
97+
'jukebox',
98+
'jumbo',
99+
'kayak',
100+
'kazoo',
101+
'keyhole',
102+
'khaki',
103+
'kilobyte',
104+
'kiosk',
105+
'kitsch',
106+
'kiwifruit',
107+
'klutz',
108+
'knapsack',
109+
'larynx',
110+
'lengths',
111+
'lucky',
112+
'luxury',
113+
'lymph',
114+
'marquis',
115+
'matrix',
116+
'megahertz',
117+
'microwave',
118+
'mnemonic',
119+
'mystify',
120+
'naphtha',
121+
'nightclub',
122+
'nowadays',
123+
'numbskull',
124+
'nymph',
125+
'onyx',
126+
'ovary',
127+
'oxidize',
128+
'oxygen',
129+
'pajama',
130+
'peekaboo',
131+
'phlegm',
132+
'pixel',
133+
'pizazz',
134+
'pneumonia',
135+
'polka',
136+
'pshaw',
137+
'psyche',
138+
'puppy',
139+
'puzzling',
140+
'quartz',
141+
'queue',
142+
'quips',
143+
'quixotic',
144+
'quiz',
145+
'quizzes',
146+
'quorum',
147+
'razzmatazz',
148+
'rhubarb',
149+
'rhythm',
150+
'rickshaw',
151+
'schnapps',
152+
'scratch',
153+
'shiv',
154+
'snazzy',
155+
'sphinx',
156+
'spritz',
157+
'squawk',
158+
'staff',
159+
'strength',
160+
'strengths',
161+
'stretch',
162+
'stronghold',
163+
'stymied',
164+
'subway',
165+
'swivel',
166+
'syndrome',
167+
'thriftless',
168+
'thumbscrew',
169+
'topaz',
170+
'transcript',
171+
'transgress',
172+
'transplant',
173+
'triphthong',
174+
'twelfth',
175+
'twelfths',
176+
'unknown',
177+
'unworthy',
178+
'unzip',
179+
'uptown',
180+
'vaporize',
181+
'vixen',
182+
'vodka',
183+
'voodoo',
184+
'vortex',
185+
'voyeurism',
186+
'walkway',
187+
'waltz',
188+
'wave',
189+
'wavy',
190+
'waxy',
191+
'wellspring',
192+
'wheezy',
193+
'whiskey',
194+
'whizzing',
195+
'whomever',
196+
'wimpy',
197+
'witchcraft',
198+
'wizard',
199+
'woozy',
200+
'wristwatch',
201+
'wyvern',
202+
'xylophone',
203+
'yachtsman',
204+
'yippee',
205+
'yoked',
206+
'youthful',
207+
'yummy',
208+
'zephyr',
209+
'zigzag',
210+
'zigzagging',
211+
'zilch',
212+
'zipper',
213+
'zodiac',
214+
'zombie',
215+
]

Python/main.py

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
import hangman_art
2+
import hangman_words
3+
import random
4+
from os import system, name
5+
def clear():
6+
7+
# for windows
8+
if name == 'nt':
9+
_ = system('cls')
10+
11+
# for mac and linux(here, os.name is 'posix')
12+
else:
13+
_ = system('clear')
14+
15+
print(hangman_art.logo)
16+
end_of_game = False
17+
chosen_word = random.choice(hangman_words.word_list)
18+
word_length = len(chosen_word)
19+
20+
lives = 7
21+
22+
#Create blanks
23+
display = []
24+
for _ in range(word_length):
25+
display += "_"
26+
27+
while not end_of_game:
28+
guess = input("\nGuess a letter: ").lower()
29+
30+
clear()
31+
32+
if guess in display:
33+
print("\nYou have already entered the letter.")
34+
continue
35+
36+
if guess not in chosen_word:
37+
lives -= 1
38+
print(f"\nWrong guess! Lives remaining: {lives}\n{hangman_art.stages[lives]}")
39+
if lives == 0:
40+
print("No lives remaining. You lose!")
41+
print(f"\nThe word was {chosen_word}.")
42+
end_of_game = True
43+
continue
44+
print(f"{' '.join(display)}")
45+
continue
46+
47+
#Check guessed letter
48+
for position in range(word_length):
49+
letter = chosen_word[position]
50+
if letter == guess:
51+
display[position] = letter
52+
print("\nCorrect!")
53+
54+
#Join all the elements in the list and turn it into a String.
55+
print(f"{' '.join(display)}")
56+
57+
#Check if user has got all letters.
58+
if "_" not in display:
59+
end_of_game = True
60+
print("\nYou win!")

0 commit comments

Comments
 (0)