1
1
import random
2
- from collections import Counter
2
+ from collections import Counter
3
3
4
- fruits = '''apple banana mango strawberry
5
- orange grape pineapple apricot lemon coconut watermelon
6
- cherry papaya berry peach lychee muskmelon'''
7
-
8
- animals = '''tiger lion elephant leopord gorilla hyena panther camel alligator panda mole'''
4
+ fruits = '''mango banana strawbarry apple leamon tomato'''
5
+ animals = '''tiger lion chita rabit snake elephant giraffe'''
9
6
10
7
fruitList = fruits .split ()
11
8
animalList = animals .split ()
12
9
13
- word_category = {word :'fruit' for word in fruitList }
14
- word_category .update ({word :'animal' for word in animalList })
10
+ word_Category = {word :'fruit' for word in fruitList }
11
+ word_Category .update ({word : 'animal' for word in animalList })
15
12
16
13
wordList = fruitList + animalList
17
14
word = random .choice (wordList )
18
- category = word_category [word ]
15
+ category = word_Category [word ]
19
16
print (word )
20
- if __name__ == '__main__' :
21
- print (f'Guess the Word! : Hint -> Category { category } ' )
22
-
17
+ if __name__ == '__main__' :
18
+ print (f'Guess the word! : Hint - Category { category } ' )
19
+
20
+ for i in word :
21
+ print ("_" , end = "" )
22
+ print ()
23
+
23
24
rounds = len (word ) + 2
24
- print (f'------> Total Number of Rounds { rounds } <------' )
25
- letterGuessed = ''
26
- correct = 0
27
25
flag = 0
26
+ letterGuessed = ''
28
27
28
+ print (f'---> Total Number of Rounds : { rounds } <---' )
29
29
try :
30
- for i in word :
31
- print ("_" , end = " " )
32
- print ()
33
30
while (rounds and flag == 0 ):
34
- guess = input ("Enter a letter : " )
35
- if not guess .isalpha ():
36
- print ("Only Letters are Allowed !!!" )
37
- continue
31
+ guess = input ("Inter a letter : " )
32
+ if not guess .isalpha :
33
+ print ("Only Alhpabetic Character Allowed" )
38
34
if len (guess ) != 1 :
39
- print ("Please Enter only Once Letter at a time" )
40
- continue
41
-
35
+ print ("Only Once Character Allowed at a Time" )
42
36
if guess in word :
43
- c = word .count (guess )
44
- for _ in range (c ):
37
+ w = word .count (guess )
38
+ for _ in range (w ):
45
39
letterGuessed += guess
46
-
47
40
for char in word :
48
41
if char in letterGuessed and (Counter (letterGuessed ) != Counter (word )):
49
42
print (char , end = " " )
50
- correct += 1
51
- elif (Counter (letterGuessed ) == Counter (word )):
52
- print (f'The word is : ' , end = " " )
53
- print (word )
43
+ elif (Counter (letterGuessed ) == Counter (word )):
54
44
flag = 1
55
- print ("Congratulations ***" )
45
+ print (f'The word is : { word } ' )
46
+ print ("*** Congratulations ***" )
56
47
break
57
48
break
58
49
else :
59
- print ('_' , end = " " )
50
+ print ("_" , end = " " )
60
51
rounds -= 1
61
52
62
53
if rounds <= 0 and (Counter (letterGuessed ) != Counter (word )):
63
54
print ()
64
- print ("You Lost the Game !!! " )
65
- print ('The word is {}' . format ( word ) )
55
+ print ("You Lose the Game" )
56
+ print (f 'The word is { word } ' )
66
57
67
58
except KeyboardInterrupt :
68
59
print ()
69
- print ("Bye! Try Again... " )
70
- exit ()
60
+ print ("Bye! Try Next Time " )
61
+ exit ()
0 commit comments