In: Computer Science
def playable(word, hand):
'''Given a word and a hand, check if a word can be
made based on the hand you are given.
return True if word can be played or False if no word
can be made
hand and False if not. For example:
playable("ZOO", ['Z', 'B', 'O', 'I', 'J', 'O', 'K'])
--> True
playable("ELEPHANT", ['H','O',]) -->
False
playable("DOG", ['O', 'S', 'Q', 'W', 'O', 'D', 'K'])
--> False
playable("ZOOM", ['V', 'M', 'O', 'N', 'Z', 'R', 'D'])
--> False.'''
ZOOM is False since missing another O
scrabble code that checks if word is playable based on hand on python
will thumbs up
Python code is pasted below.
#function definition
def playable(str1,list1):
#Taking each character from the string
for char in str1:
#If character is not in string return false
if char not in list1:
return False
#Remove character from list
else:
list1.remove(char)
return True
#main program
#function calling
print(playable("ZOO",["Z","B","O","I","J","O","K"]))
print(playable("ELEPHANT", ['H','O']))
print(playable("DOG", ['O', 'S', 'Q', 'W', 'O', 'D', 'K']))
print(playable("ZOOM", ['V', 'M', 'O', 'N', 'Z', 'R', 'D']))
Python code in IDLE pasted below for better understanding of the indent.
Output Screen