Skip to content

Hangman Game using Python #71

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 22, 2021
Merged
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
Binary file added Hangman/__pycache__/hangman_art.cpython-36.pyc
Binary file not shown.
Binary file added Hangman/__pycache__/hangman_words.cpython-36.pyc
Binary file not shown.
55 changes: 55 additions & 0 deletions Hangman/hangman.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
from hangman_art import logo , stages
from hangman_words import wordlist
import random

# get random word from hangman_words
random_word = random.choice(wordlist)
word_len = len(random_word)

print(logo)
print('This is your word.Try to guess it!!')
print('Word : ',end =" ")

guess_word = ['_'] * word_len
print(*guess_word)

chances = 6
end_of_game = False

# game logic
while not end_of_game and chances != 0:

flag = 0
letter = input('\n\nGuess a letter: ').lower()

if (letter.isdigit() or len(letter) != 1):
print('Please enter single letter (Numbers not allowed)')
continue

if letter in guess_word:
print(f"You've already guessed {letter}")

for i in range(word_len):
if random_word[i] == letter:
guess_word[i] = letter
flag = 1

if '_' not in guess_word:
end_of_game = True
print('\nCongo!! You won. :)')
break

if flag == 0:
print(f"You guessed {letter}, that's not in the word. You lose a life")
chances -= 1

print('Guessed Word : ',end =" ")
print(*guess_word)
print(stages[6-chances])

else:
print('\nYou lost :(\nCorrect word:',random_word)




61 changes: 61 additions & 0 deletions Hangman/hangman_art.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
logo = '''
_
| |
| |__ __ _ _ __ __ _ _ __ ___ __ _ _ __
| '_ \ / _` | '_ \ / _` | '_ ` _ \ / _` | '_ \
| | | | (_| | | | | (_| | | | | | | (_| | | | |
|_| |_|\__,_|_| |_|\__, |_| |_| |_|\__,_|_| |_|
__/ |
|___/
'''

stages = ['''
+---+
| |
|
|
|
|
=========''', '''
+---+
| |
O |
|
|
|
=========''', '''
+---+
| |
O |
| |
|
|
=========''', '''
+---+
| |
O |
/| |
|
|
=========''', '''
+---+
| |
O |
/|\ |
|
|
=========''', '''
+---+
| |
O |
/|\ |
/ |
|
=========''', '''
+---+
| |
O |
/|\ |
/ \ |
|
=========''']
19 changes: 19 additions & 0 deletions Hangman/hangman_words.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
wordlist = [
'kangaroo',
'basketball',
'pinch',
'pillow',
'elephant',
'prayer',
'telephone',
'hopscotch',
'scissors',
'alligator',
'inchworm',
'snowman',
'walkway',
'wristwatch',
'youthful',
'twilight',
'fisherman',
'baboon']