Skip to content

Commit 4b523b7

Browse files
committed
Hangman_Game_project.py
1 parent 79706d0 commit 4b523b7

File tree

4 files changed

+106
-0
lines changed

4 files changed

+106
-0
lines changed

Hangman_Game_project.py

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import random
2+
import hangman_stages
3+
word_list=["Apple","Nice","beautiful","potato"]
4+
chosen_word=random.choice(word_list)
5+
print(chosen_word)
6+
display=[]
7+
for i in range(len(chosen_word)):
8+
display+='_'
9+
print(display)
10+
lives = len(chosen_word)
11+
game_over=False
12+
while not game_over:
13+
guessed_letter=input("Guess a letter:").lower()
14+
for position in range(len(chosen_word)):
15+
letter=chosen_word[position]
16+
if letter==guessed_letter:
17+
display[position]=guessed_letter
18+
print(display)
19+
if guessed_letter not in chosen_word:
20+
lives-=1
21+
if lives == 0:
22+
game_over = True
23+
print("You lose")
24+
if '_' not in display:
25+
game_over=True
26+
print("You win")
27+
print(hangman_stages.stages[lives])
28+
29+
864 Bytes
Binary file not shown.

hangman_stages.py

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
stages = [
2+
'''
3+
+---+
4+
| |
5+
O |
6+
/|\\ |
7+
/ \\ |
8+
|
9+
=========
10+
''',
11+
'''
12+
+---+
13+
| |
14+
O |
15+
/|\\ |
16+
/ |
17+
|
18+
=========
19+
''',
20+
'''
21+
+---+
22+
| |
23+
O |
24+
/|\\ |
25+
|
26+
|
27+
=========
28+
''',
29+
'''
30+
+---+
31+
| |
32+
O |
33+
/| |
34+
|
35+
|
36+
=========
37+
''',
38+
'''
39+
+---+
40+
| |
41+
O |
42+
| |
43+
|
44+
|
45+
=========
46+
''',
47+
'''
48+
+---+
49+
| |
50+
O |
51+
|
52+
|
53+
|
54+
=========
55+
''',
56+
'''
57+
+---+
58+
| |
59+
|
60+
|
61+
|
62+
|
63+
=========
64+
'''
65+
]

identation.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,15 @@
55
for i in range(5):
66
print("Hi")
77
print("Jenny")
8+
9+
for i in range(5):
10+
print("Hi")
11+
print("Jenny")
12+
13+
14+
for i in range(5):
15+
print("Hi")
16+
print("Jenny")
17+
if i==3:
18+
print("Welcome")
19+
print("bye take care")

0 commit comments

Comments
 (0)