-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHangman.py
50 lines (40 loc) · 1.47 KB
/
Hangman.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
import random
import hangman_data
#logo call
print(hangman_data.logo)
lives = 6
chosen_word = random.choice(hangman_data.words_library)
# print(chosen_word)
guessed_letter = []
blanks =" "
for letter in chosen_word:
blanks = blanks+"_ "
print(blanks)
game_over = False
while not game_over:
display = " "
print(f"\n=====================================<< Lives left = {lives} >>=====================================")
guess = input("Enter letter: ")
for letter in chosen_word:
if letter == guess:
display = display + guess +" "
guessed_letter.append(guess)
elif letter in guessed_letter:
display = display + letter+" "
else:
display = display + "_ "
if guess not in guessed_letter:
lives = lives-1
print(f"You guessed "+ guess+", which is not present in the word")
print(f"Remaining lives = {lives}")
print(hangman_data.hangman_art[lives])
print(display)
if lives == 0:
game_over = True
print("\n=====================================<< YOU LOOSE >>=====================================")
print("\nThe Correct word was = "+ chosen_word+". Better luck next time :)")
if '_' not in display:
game_over = True
print("\n=====================================<< YOU WON >>=====================================")
input("press ENTER to exit")
print(hangman_data.creator)