8000 Add files via upload · techbire/python-project@b5cc679 · GitHub
[go: up one dir, main page]

Skip to content

Commit b5cc679

Browse files
authored
Add files via upload
1 parent 6543cea commit b5cc679

File tree

3 files changed

+147
-0
lines changed

3 files changed

+147
-0
lines changed

Hangman/hangman_art.py

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

Hangman/hangman_words.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
word_list = [
2+
'ansh gupta',
3+
'abhishek',
4+
'techbire',
5+
'shrija',
6+
'raj',
7+
'anurag',
8+
'shivani',
9+
'shristi',
10+
'khushi',
11+
'swati',
12+
'anshika',
13+
'prakhar',
14+
'akash',
15+
'rachit',
16+
'rishabh',
17+
]

Hangman/main.py

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
#Step 5
2+
3+
import random
4+
5+
#TODO-1: - Update the word list to use the 'word_list' from hangman_words.py
6+
#Delete this line: word_list = ["ardvark", "baboon", "camel"]
7+
from hangman_words import word_list
8+
9+
chosen_word = random.choice(word_list)
10+
word_length = len(chosen_word)
11+
12+
end_of_game = False
13+
lives = 6
14+
15+
#TODO-3: - Import the logo from hangman_art.py and print it at the start of the game.
16+
from hangman_art import logo
17+
print(logo)
18+
19+
#Testing code
20+
print(f'Pssst, the solution is {chosen_word}.')
21+
22+
#Create blanks
23+
display = []
24+
for _ in range(word_length):
25+
display += "_"
26+
27+
while not end_of_game:
28+
guess = input("Guess a letter: ").lower()
29+
30+
#TODO-4: - If the user has entered a letter they've already guessed, print the letter and let them know.
31+
if guess in display:
32+
print(f"You've already guessed {guess}")
33+
34+
#Check guessed letter
35+
for position in range(word_length):
36+
letter = chosen_word[position]
37+
#print(f"Current position: {position}\n Current letter: {letter}\n Guessed letter: {guess}")
38+
if letter == guess:
39+
display[position] = letter
40+
41+
#Check if user is wrong.
42+
if guess not in chosen_word:
43+
#TODO-5: - If the letter is not in the chosen_word, print out the letter and let them know it's not in the word.
44+
print(f"You guessed {guess}, that's not in the word. You lose a life.")
45+
46+
lives -= 1
47+
if lives == 0:
48+
end_of_game = True
49+
print("You lose.")
50+
51+
#Join all the elements in the list and turn it into a String.
52+
print(f"{' '.join(display)}")
53+
54+
#Check if user has got all letters.
55+
if "_" not in display:
56+
end_of_game = True
57+
print("You win.")
58+
59+
#TODO-2: - Import the stages from hangman_art.py and make this error go away.
60+
from hangman_art import stages
61+
print(stages[lives])

0 commit comments

Comments
 (0)
0