-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
68 lines (58 loc) · 1.84 KB
/
main.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# importing modules inbuilt and user define
import random
import hangman_art
import hangman_word
# variables
end_of_game = False
display = []
chosen_word = random.choice(hangman_word.word_list)
logo = hangman_art.logo
stages = hangman_art.stages
len_of_word = len(chosen_word)
# lives
lives = 6
# extra feature optional
incorrect_guess = []
# print logo of game
print(logo)
# display word blanks space
for pos in chosen_word:
display += "_"
# main code
while not end_of_game:
guess = input("\nguess a letter\n : ").lower()
# checking for repeating correct guess
if guess in display:
print("hey! you have already guessed that letter.")
# check with every letter
else:
for i in range(len_of_word):
if chosen_word[i] == guess:
display[i] = guess
# user exprience
if guess in chosen_word:
print("\nWhoooooho you are winning")
# user experience
if guess in incorrect_guess:
print("\nHey! you'r repeating your mistakes.")
print("So, I'm not taking your life!")
else:
# FOR WRONG CASE LOOSE LIFE
if guess not in chosen_word:
lives -= 1 # taking lives
# printing hangman art
print(stages[lives])
# puttin in incorrect guess in list
incorrect_guess.append(guess)
# user exprience
print(f"Oopps! this letter '{guess}' not in word.")
# losing condition
if lives == 0:
end_of_game = True
print("\nYou loose!")
print(f"\nYou dummy word was... \n: '{chosen_word}'")
# conditin of winning
if "_" not in display:
end_of_game = True
print("you won!!")
print(f"{' '.join(display)}")