Skip to content
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
39 changes: 39 additions & 0 deletions hangman.py
Original file line number Diff line number Diff line change
@@ -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))