From c12757d1ce48817864c3c93c5f9d73c673727a3d Mon Sep 17 00:00:00 2001 From: Keshav Rathod <43353280+codedoc7@users.noreply.github.com> Date: Mon, 5 Oct 2020 00:47:21 +0530 Subject: [PATCH] Add files via upload --- hangman.py | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 hangman.py diff --git a/hangman.py b/hangman.py new file mode 100644 index 0000000..2835893 --- /dev/null +++ b/hangman.py @@ -0,0 +1,39 @@ +def hangman(word): + wrong=0 + stages=["", + " __________ ", + "| ", + "| | ", + "| | ", + "| 0 ", + "| /|\ ", + "| / \ ", + "| " + ] + remaining_letters=list(word) + board=["__"]* len(word) + win=False + print("Welcome to Hangman") + + while wrong < len(stages)-1: + print('\n') + msg="Guess a letter" + char=input(msg) + if char in remaining_letters: + cind=remaining_letters.index(char) + board[cind]=char + remaining_letters[cind]="$" + else: + wrong+=1 + print((" ".join(board))) + e=wrong+1 + print("\n".join(stages[0:e])) + if "__" not in board: + print("You win!") + print(" ".join(board)) + win=True + break + if not win: + print("\n".join(stages[0:wrong])) + print("You lose! It was{}.".format(word)) +