From ebce3dbe99464d0e416134838babb8d9b44d1f02 Mon Sep 17 00:00:00 2001 From: Vivek <92520077+sahutheboss@users.noreply.github.com> Date: Sat, 8 Oct 2022 18:31:45 +0530 Subject: [PATCH] Created hangman_game.py edit code for hangman game --- Python/hangman_game.py | 174 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 174 insertions(+) create mode 100644 Python/hangman_game.py diff --git a/Python/hangman_game.py b/Python/hangman_game.py new file mode 100644 index 00000000..fdd09ebb --- /dev/null +++ b/Python/hangman_game.py @@ -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!")