Skip to content

Commit 85d94f8

Browse files
authored
Create hangmanproject_unit8.py
1 parent 9c3bb3e commit 85d94f8

File tree

1 file changed

+69
-0
lines changed

1 file changed

+69
-0
lines changed

Diff for: hangmanproject_unit8.py

+69
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
# hangman project - unit 8 exercise
2+
# author - lirom mizrahi
3+
'''
4+
Towards the end of the development of the game "Hanged Man" we had to go back and print each time one of the status images of the hanging man, depending on the number of wrong guesses the player guessed.
5+
6+
For this purpose, follow the following instructions:
7+
8+
Define a constant variable called HANGMAN_PHOTOS. The variable is of dictionary type (dict) and must hold the seven states of the hanging man (which you encountered in the unfolding task at the end of Unit 1).
9+
Write a function called print_hangman defined as follows:
10+
def print_hangman(num_of_tries):
11+
The function prints one of the seven states of the hanging man, using:
12+
A variable called num_of_tries that represents the number of failed attempts by the user so far.
13+
The HANGMAN_PHOTOS variable you defined.
14+
An example of running the print_hangman function
15+
>>> num_of_tries = 6
16+
>>> print_hangman(num_of_tries)
17+
x-------x
18+
| |
19+
| 0
20+
| /|\
21+
| / \
22+
|
23+
'''
24+
def print_hangman(num_of_tries):
25+
HANGMAN_PHOTOS = {
26+
1: """ x-------x""",
27+
2: """ x-------x
28+
|
29+
|
30+
|
31+
|
32+
|""",
33+
3: """ x-------x
34+
| |
35+
| 0
36+
|
37+
|
38+
|""",
39+
4: """ x-------x
40+
| |
41+
| 0
42+
| |
43+
|
44+
|""",
45+
5: """ x-------x
46+
| |
47+
| 0
48+
| /|\
49+
|
50+
|""",
51+
6: """ x-------x
52+
| |
53+
| 0
54+
| /|\
55+
| /
56+
|""",
57+
7: ''' x-------x
58+
| |
59+
| 0
60+
| /|
61+
| /
62+
|'''
63+
}
64+
if num_of_tries in HANGMAN_PHOTOS.keys():
65+
print(HANGMAN_PHOTOS[num_of_tries])
66+
else:
67+
print('X')
68+
69+
print(print_hangman(7))

0 commit comments

Comments
 (0)