Skip to content

Created hangman_game.py #375

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
174 changes: 174 additions & 0 deletions Python/hangman_game.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,174 @@
import random
print('''

██████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████
█░░░░░░██████████░░░░░░█░░░░░░░░░░░░░░█░░░░░░█████████░░░░░░░░░░░░░░█░░░░░░░░░░░░░░█░░░░░░██████████░░░░░░█░░░░░░░░░░░░░░█
█░░▄▀░░██████████░░▄▀░░█░░▄▀▄▀▄▀▄▀▄▀░░█░░▄▀░░█████████░░▄▀▄▀▄▀▄▀▄▀░░█░░▄▀▄▀▄▀▄▀▄▀░░█░░▄▀░░░░░░░░░░░░░░▄▀░░█░░▄▀▄▀▄▀▄▀▄▀░░█
█░░▄▀░░██████████░░▄▀░░█░░▄▀░░░░░░░░░░█░░▄▀░░█████████░░▄▀░░░░░░░░░░█░░▄▀░░░░░░▄▀░░█░░▄▀▄▀▄▀▄▀▄▀▄▀▄▀▄▀▄▀░░█░░▄▀░░░░░░░░░░█
█░░▄▀░░██████████░░▄▀░░█░░▄▀░░█████████░░▄▀░░█████████░░▄▀░░█████████░░▄▀░░██░░▄▀░░█░░▄▀░░░░░░▄▀░░░░░░▄▀░░█░░▄▀░░█████████
█░░▄▀░░██░░░░░░██░░▄▀░░█░░▄▀░░░░░░░░░░█░░▄▀░░█████████░░▄▀░░█████████░░▄▀░░██░░▄▀░░█░░▄▀░░██░░▄▀░░██░░▄▀░░█░░▄▀░░░░░░░░░░█
█░░▄▀░░██░░▄▀░░██░░▄▀░░█░░▄▀▄▀▄▀▄▀▄▀░░█░░▄▀░░█████████░░▄▀░░█████████░░▄▀░░██░░▄▀░░█░░▄▀░░██░░▄▀░░██░░▄▀░░█░░▄▀▄▀▄▀▄▀▄▀░░█
█░░▄▀░░██░░▄▀░░██░░▄▀░░█░░▄▀░░░░░░░░░░█░░▄▀░░█████████░░▄▀░░█████████░░▄▀░░██░░▄▀░░█░░▄▀░░██░░░░░░██░░▄▀░░█░░▄▀░░░░░░░░░░█
█░░▄▀░░░░░░▄▀░░░░░░▄▀░░█░░▄▀░░█████████░░▄▀░░█████████░░▄▀░░█████████░░▄▀░░██░░▄▀░░█░░▄▀░░██████████░░▄▀░░█░░▄▀░░█████████
█░░▄▀▄▀▄▀▄▀▄▀▄▀▄▀▄▀▄▀░░█░░▄▀░░░░░░░░░░█░░▄▀░░░░░░░░░░█░░▄▀░░░░░░░░░░█░░▄▀░░░░░░▄▀░░█░░▄▀░░██████████░░▄▀░░█░░▄▀░░░░░░░░░░█
█░░▄▀░░░░░░▄▀░░░░░░▄▀░░█░░▄▀▄▀▄▀▄▀▄▀░░█░░▄▀▄▀▄▀▄▀▄▀░░█░░▄▀▄▀▄▀▄▀▄▀░░█░░▄▀▄▀▄▀▄▀▄▀░░█░░▄▀░░██████████░░▄▀░░█░░▄▀▄▀▄▀▄▀▄▀░░█
█░░░░░░██░░░░░░██░░░░░░█░░░░░░░░░░░░░░█░░░░░░░░░░░░░░█░░░░░░░░░░░░░░█░░░░░░░░░░░░░░█░░░░░░██████████░░░░░░█░░░░░░░░░░░░░░█
██████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████
''')
print('''

───────────────────────────────
─██████████████─██████████████─
─██░░░░░░░░░░██─██░░░░░░░░░░██─
─██████░░██████─██░░██████░░██─
─────██░░██─────██░░██──██░░██─
─────██░░██─────██░░██──██░░██─
─────██░░██─────██░░██──██░░██─
─────██░░██─────██░░██──██░░██─
─────██░░██─────██░░██──██░░██─
─────██░░██─────██░░██████░░██─
─────██░░██─────██░░░░░░░░░░██─
─────██████─────██████████████─
───────────────────────────────
''')
print('''


██╗░░██╗░█████╗░███╗░░██╗░██████╗░███╗░░░███╗░█████╗░███╗░░██╗   ░██████╗░░█████╗░███╗░░░███╗███████╗
██║░░██║██╔══██╗████╗░██║██╔════╝░████╗░████║██╔══██╗████╗░██║   ██╔════╝░██╔══██╗████╗░████║██╔════╝
███████║███████║██╔██╗██║██║░░██╗░██╔████╔██║███████║██╔██╗██║   ██║░░██╗░███████║██╔████╔██║█████╗░░
██╔══██║██╔══██║██║╚████║██║░░╚██╗██║╚██╔╝██║██╔══██║██║╚████║   ██║░░╚██╗██╔══██║██║╚██╔╝██║██╔══╝░░
██║░░██║██║░░██║██║░╚███║╚██████╔╝██║░╚═╝░██║██║░░██║██║░╚███║   ╚██████╔╝██║░░██║██║░╚═╝░██║███████╗
╚═╝░░╚═╝╚═╝░░╚═╝╚═╝░░╚══╝░╚═════╝░╚═╝░░░░░╚═╝╚═╝░░╚═╝╚═╝░░╚══╝   ░╚═════╝░╚═╝░░╚═╝╚═╝░░░░░╚═╝╚══════╝


''')

print('''


█▀▀ ▄▀█ █▀▄▀█ █▀▀   █▀█ █░░ ▄▀█ █▄█
█▄█ █▀█ █░▀░█ ██▄   █▀▀ █▄▄ █▀█ ░█░

''')


print('''
1. The computer will give you a word or phrase to guess.
2. The player will try to guess the given word what it is one letter at a time.
3. The computer draws a number of dashes equivalent to the number of letters in the word.
4. If the player suggests a letter that occurs in the word, the computer will fill in the blanks with that letter in the
right places.
5. If the word does not contain the suggested letter, the computer will draw one element of a hangman’s gallows. As the
game progresses, a segment of the gallows and of a victim is added for every suggested letter not in the word.
6. The number of incorrect guesses before the game ends is up to the players, but completing a character in a noose
provides a minimum of six wrong answers until the game ends.
''')

print('''


█▀█ █▄▄ ░░█ █▀▀ █▀▀ ▀█▀ █ █░█ █▀▀   ▀
█▄█ █▄█ █▄█ ██▄ █▄▄ ░█░ █ ▀▄▀ ██▄   ▄
''')

print('''
Guess the word/phrase before your man gets hung!


''')

stages = ['''
+---+
| |
O |
/|\ |
/ \ |
|
=========
''', '''
+---+
| |
O |
/|\ |
/ |
|
=========
''', '''
+---+
| |
O |
/|\ |
|
|
=========
''', '''
+---+
| |
O |
/| |
|
|
=========''', '''
+---+
| |
O |
| |
|
|
=========
''', '''
+---+
| |
O |
|
|
|
=========
''', '''
+---+
| |
|
|
|
|
=========
''']

word_list = ["banana", "apple", "cherry","january","border","image","film","promise","kids","lungs","doll","rhyme","damage"
,"plants",'rainbow', 'computer', 'science', 'programming','python', 'mathematics', 'player', 'condition',
'reverse', 'water', 'board']
word_choice = word_list[random.randint(0, 24)]
length = len(word_choice)
lives=6
start=int(input("Press 1 to start the game!\n"))
if start == 1:
display = []
for _ in range(length):
display += "_"
print(f"{' '.join(display)}")

end_of_game = False
while end_of_game == False:
guess = input("\nGuess a letter \n").lower()

for pos in range(length):
letter = word_choice[pos]
if (letter == guess):
display[pos] = letter
if guess not in word_choice:
lives-=1
if lives == 0:
end_of_game = True

print(f"{' '.join(display)}")
print(stages[lives])
if lives==0:
print("You Loose!")
print("You failed to guess the correct word!")
print(f"The correct world is: {word_choice} ")
if "_" not in display:
end_of_game = True
print("You Win!")
else:
print("You entered wrong choice!")