-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathguessWords.py
More file actions
29 lines (29 loc) · 897 Bytes
/
guessWords.py
File metadata and controls
29 lines (29 loc) · 897 Bytes
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
import random
choice="Y"
wordList = ["apple","oranges","Titanic","Harbour","Chine"]
def checkInput(char,word):
occurrence=0
if (len(char) == 1 ):
for w in word:
if ( char.upper() == w.upper() ):
occurrence = occurrence + 1
print ("your guessed word - " + str(occurrence) )
else:
print ("Not valid input")
return occurrence
while (choice == "Y" ):
word = random.choice(wordList)
charCount = len(word)
occurrence = 0
attempt = 0
while ( attempt < 8 ):
letter = raw_input("Please guess the letters!")
occurrence = occurrence + checkInput(letter,word)
if (occurrence == len(word)):
print ("you guessed it right and word is " + word)
break
elif (attempt == 8):
print ("You exhausted the attempt!!!")
attempt = attempt + 1
print ("Attempt remaining - " + str(8-attempt))
choice = raw_input("Press Y to play it again and N to exit")