-
Notifications
You must be signed in to change notification settings - Fork 168
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #428 from amilbhat/master
Added hangman to python #427
- Loading branch information
Showing
3 changed files
with
323 additions
and
0 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import random | ||
from hangman_art import stages, logo | ||
from hangman_words import word_list | ||
|
||
print(logo) | ||
game_is_finished = False | ||
lives = len(stages) - 1 | ||
|
||
chosen_word = random.choice(word_list) | ||
word_length = len(chosen_word) | ||
|
||
display = [] | ||
for _ in range(word_length): | ||
display += "_" | ||
|
||
while not game_is_finished: | ||
guess = input("Guess a letter: ").lower() | ||
|
||
if guess in display: | ||
print(f"You've already guessed {guess}") | ||
|
||
for position in range(word_length): | ||
letter = chosen_word[position] | ||
if letter == guess: | ||
display[position] = letter | ||
print(f"{' '.join(display)}") | ||
|
||
if guess not in chosen_word: | ||
print(f"You guessed {guess}, that's not in the word. You lose a life.") | ||
lives -= 1 | ||
if lives == 0: | ||
game_is_finished = True | ||
print("You lose.") | ||
|
||
if not "_" in display: | ||
game_is_finished = True | ||
print("You win.") | ||
|
||
print(stages[lives]) |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
stages = [''' | ||
+---+ | ||
| | | ||
O | | ||
/|\ | | ||
/ \ | | ||
| | ||
========= | ||
''', ''' | ||
+---+ | ||
| | | ||
O | | ||
/|\ | | ||
/ | | ||
| | ||
========= | ||
''', ''' | ||
+---+ | ||
| | | ||
O | | ||
/|\ | | ||
| | ||
| | ||
========= | ||
''', ''' | ||
+---+ | ||
| | | ||
O | | ||
/| | | ||
| | ||
| | ||
=========''', ''' | ||
+---+ | ||
| | | ||
O | | ||
| | | ||
| | ||
| | ||
========= | ||
''', ''' | ||
+---+ | ||
| | | ||
O | | ||
| | ||
| | ||
| | ||
========= | ||
''', ''' | ||
+---+ | ||
| | | ||
| | ||
| | ||
| | ||
| | ||
========= | ||
'''] | ||
|
||
logo = ''' | ||
_ | ||
| | | ||
| |__ __ _ _ __ __ _ _ __ ___ __ _ _ __ | ||
| '_ \ / _` | '_ \ / _` | '_ ` _ \ / _` | '_ \ | ||
| | | | (_| | | | | (_| | | | | | | (_| | | | | | ||
|_| |_|\__,_|_| |_|\__, |_| |_| |_|\__,_|_| |_| | ||
__/ | | ||
|___/ ''' | ||
|
||
|
||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,215 @@ | ||
word_list = [ | ||
'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', | ||
] |
6048a98
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
open-source-contribution-for-beginners – ./
open-source-contribution-for-beginners-cyberbuddy.vercel.app
open-source-contribution-for-beginners.vercel.app
open-source-contribution-for-beginners-git-master-cyberbuddy.vercel.app
opensource.cyberbuddy.live