Skip to content

Commit a30d428

Browse files
committed
Adding third Project
1 parent 9fc38d8 commit a30d428

File tree

1 file changed

+29
-38
lines changed

1 file changed

+29
-38
lines changed

Project 3 - Hungman Game/main.py

+29-38
Original file line numberDiff line numberDiff line change
@@ -1,70 +1,61 @@
11
import random
2-
from collections import Counter
2+
from collections import Counter
33

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'''
96

107
fruitList = fruits.split()
118
animalList = animals.split()
129

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})
1512

1613
wordList = fruitList + animalList
1714
word = random.choice(wordList)
18-
category = word_category[word]
15+
category = word_Category[word]
1916
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+
2324
rounds = len(word) + 2
24-
print(f'------> Total Number of Rounds {rounds} <------')
25-
letterGuessed = ''
26-
correct = 0
2725
flag = 0
26+
letterGuessed = ''
2827

28+
print(f'---> Total Number of Rounds : {rounds} <---')
2929
try:
30-
for i in word:
31-
print("_", end=" ")
32-
print()
3330
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")
3834
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")
4236
if guess in word:
43-
c = word.count(guess)
44-
for _ in range(c):
37+
w = word.count(guess)
38+
for _ in range(w):
4539
letterGuessed += guess
46-
4740
for char in word:
4841
if char in letterGuessed and (Counter(letterGuessed) != Counter(word)):
4942
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)):
5444
flag = 1
55-
print("Congratulations ***")
45+
print(f'The word is : {word}')
46+
print("*** Congratulations ***")
5647
break
5748
break
5849
else:
59-
print('_', end=" ")
50+
print("_", end=" ")
6051
rounds -= 1
6152

6253
if rounds <= 0 and (Counter(letterGuessed) != Counter(word)):
6354
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}')
6657

6758
except KeyboardInterrupt:
6859
print()
69-
print("Bye! Try Again...")
70-
exit()
60+
print("Bye! Try Next Time")
61+
exit()

0 commit comments

Comments
 (0)