Should Return True if word is in the word_list and is entirely composed of letters in the hand. Otherwise, returns False.
def is_valid_word(word, hand, word_list):
### word = string, hand = dictionary, word_list = string
count = 0
for letter in word:
if letter in hand and word_list:
count += 1
if count == len(word):
return True
else:
return False
is_valid_word('star', {'a': 0, 's': 3, 'i': 0, 'e': 1, 'l': 1, 't': 3,'r':1}, 'sctdahr') ##returns true
is_valid_word('star', {'i': 0, 'e': 1, 'l': 1, 't': 3,'r':1}, 'sctdahr') ###returns false
is_valid_word('star', {'a': 0, 's': 3, 'i': 0, 'e': 1, 'l': 1, 't': 3,'r':1}, 'sc') ###returns true
Why the last statement is returning True instead of False?
Aucun commentaire:
Enregistrer un commentaire