-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathHangman.py
147 lines (130 loc) · 5.26 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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
#Hangman game is a guessing game.
#You have given a word from an unknown list and you have to guess the word by entering characters
import random
friends_name = ["divyanshu", "nirmal", "nisha", "palash", "priyanshu", "prakhar", "rahul", "tanushree", "zuber"]
avengers_name = ["blackwidow", "captainamerica", "captainmarvel", "doctorstrange", "hulk", "ironman", "spiderman", "thor"]
language_name = ["chinese", "dutch", "english", "french", "hindi", "sanskrit"]
list_of_words = [friends_name, avengers_name, language_name]
#--------------------------------------------------------------------------------------#
def hangman() :
#selecting random word
list = random.choice(list_of_words)
word = random.choice(list)
#guessed characters are stored in 'guess' for future reference
guess = ""
#updated guessed word
guess_word = ""
#list of valid characters
valid_char = "abcdefghijklmnopqrstuvwxyz"
live = 10
print("Guess the word : ", end = "")
for i in word :
print("_", end = " ")
print()
while True :
char = input("\nEnter a character : ")
if char not in valid_char :
print(" You entered an invalid character!!!")
continue
else :
if char in word:
if char not in guess :
guess += char
else :
print("You already guess this letter, try new one.")
else :
print("Your guess is wrong.")
live -= 1
#You win if you guess all letters from the word
if set(guess) == set(word) :
print(" YOU WIN (*_*) __CONGRATULATIONS__")
print("The word you guess is : " + word)
print("Thanks for saving Lokesh's life, You are such a true friend.")
break
#printing guessed letters
print("Your guess : ", end = " ")
for letter in word :
if letter in guess :
print(letter, end = " ")
else :
print("_", end = " ")
print()
print("Remainig Lives = " + str(live))
print("_______________")
if live == 9 :
print("| O |")
print("| |")
print("| |")
print("| |")
elif live == 8 :
print("| O |")
print("| | |")
print("| |")
print("| |")
elif live == 7 :
print("| \ O |")
print("| | |")
print("| |")
print("| |")
elif live == 6 :
print("| \ O / |")
print("| | |")
print("| |")
print("| |")
elif live == 5 :
print("| \ O / |")
print("| | |")
print("| / |")
print("| |")
elif live == 4 :
print("| \ O / |")
print("| | |")
print("| / \ |")
print("| |")
elif live == 3 :
print("| \ O /| |")
print("| | |")
print("| / \ |")
print("| |")
elif live == 2 :
print("| \ O /| |")
print("| | |")
print("| / \ |")
print("| |")
elif live == 1 :
print("| \ O_| |")
print("| | |")
print("| / \ |")
print("| |")
print("Last breath, be carefull (o_o)")
elif live == 0 :
print("| O_| |")
print("| /|\ |")
print("| / \ |")
print("| |")
print("You killed Lokesh. (+_+)")
print("The word was : " + word)
break
#________________________________________________________________________________#
print("\tHANGMAN(LOKESH) GAME\n")
print("A boy named Lokesh is tired from his boring life. He wants some kick in his life like devilal.")
print("So he decided to hang from ceil. But he gives a chance to his friends who can save his life.")
print("Lokesh gives a length of word and his friends have to guess the word.")
print("If friends did not guessed, he will hang like hangman.")
print("\nGUIDLINES and RULES :")
print("1.A random word is given to you, you have to guess the word by entering letters of word.")
print("2.You have only 10 lives to guess the word, in each wrong guess the lives will decrease by 1.")
print("3.You have to use only 26 letters of alphabets.")
print("4.You have to guess all unique letters in the word.")
print("5.A word may be a friend's name, international language or any avenger's name.")
print("You have to save LOKESH before he hangs.")
name = input("\nEnter Your name : ")
print("Welcome in my game " + name + " (^_^)")
print()
while True :
hangman()
choice = input("\nWant to play again (y/n): ")
if choice != 'y' :
print()
break
print("\nThanks for playing " + name + " (^_^)")