We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 99cf7d7 commit c12757dCopy full SHA for c12757d
1 file changed
hangman.py
@@ -0,0 +1,39 @@
1
+def hangman(word):
2
+ wrong=0
3
+ stages=["",
4
+ " __________ ",
5
+ "| ",
6
+ "| | ",
7
8
+ "| 0 ",
9
+ "| /|\ ",
10
+ "| / \ ",
11
+ "| "
12
+ ]
13
+ remaining_letters=list(word)
14
+ board=["__"]* len(word)
15
+ win=False
16
+ print("Welcome to Hangman")
17
+
18
+ while wrong < len(stages)-1:
19
+ print('\n')
20
+ msg="Guess a letter"
21
+ char=input(msg)
22
+ if char in remaining_letters:
23
+ cind=remaining_letters.index(char)
24
+ board[cind]=char
25
+ remaining_letters[cind]="$"
26
+ else:
27
+ wrong+=1
28
+ print((" ".join(board)))
29
+ e=wrong+1
30
+ print("\n".join(stages[0:e]))
31
+ if "__" not in board:
32
+ print("You win!")
33
+ print(" ".join(board))
34
+ win=True
35
+ break
36
+ if not win:
37
+ print("\n".join(stages[0:wrong]))
38
+ print("You lose! It was{}.".format(word))
39
0 commit comments