File tree Expand file tree Collapse file tree 1 file changed +39
-0
lines changed Expand file tree Collapse file tree 1 file changed +39
-0
lines changed Original file line number Diff line number Diff line change
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
+
You can’t perform that action at this time.
0 commit comments