HANGMAN PROJECT - DAY 6
- MHK
- Jun 27, 2020
- 1 min read
DATE: JUNE 27 / 2020
AUTHOR: MAHIR KAYA
Today, we continue with our new hint function, show_possible_matches(). This function takes only one parameter which is my_word. This is the last function we are going to implement before going to the main program function for the hangman game. So, lets get back to coding.
def show_possible_matches(my_word):
l5=[]
l7=[]
#we created two empty lists to use after
for r in wordlist:
if match_with_gaps(my_word,r)==('TRUE'):
#refers to a function we used before, if you did not check it out yet, you should.
l5.append(r)
#we added those words that seem to be a possible match with our secret word.
l6=l5[:]
#we created a copy in order to iterate over the list.
for e in l6:
#at this point, I realized that there was another problem with our #code.
#our code puts the words which include the letters that are not in the #secret word
#Into the category of possible match if they match_with_gaps()=='TRUE'
#This was a property I did not add to my last function so I decided to #add this to this one.
for i in letters_guessed:
if i!= "HINT":
if i != "QUIT":
if i not in secret_word:
if i in e:
l7.append(e)
#This part add the words that has the problem I mentioned above to an empty list to determine which words we should eliminate from our original possible_matches.
for x in l7:
if x in l5:
l5.remove(x)
#We eliminate the incorrect words from our original list.
if l5==[]:
return('NO MATCHES', l5)
else:
return('POSSIBLE MATCHES:', l5,)
# We return our list.
Comments