Question

In: Computer Science

def playable(word, hand): '''Given a word and a hand, check if a word can be made...

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

Solutions

Expert Solution

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


Related Solutions

Suppose there is a task at hand to check whether one can really save a bunch...
Suppose there is a task at hand to check whether one can really save a bunch of money on the car insurance by switching from Allstate to GEICO. Their monthly insurance premiums for various car brands are shown in the table below. Conduct a two-sample test of hypothesis at α = 0.05 significance level to determine whether it is worth switching to GEICO. Car Brands GEICO Allstate Honda 120 136 Toyota 125 135 Nissan 122 135 Ford 107 102 Chevrolet...
Write 3 pages about Ionic bond You can use word or hand writing
Write 3 pages about Ionic bond You can use word or hand writing
How many 5 - letter combinations can be made from the word STAIR : a ....
How many 5 - letter combinations can be made from the word STAIR : a . With no restrictions b . If the vowels cannot be side by side
Check in each case whether the given function can serve as the probability distribution of an...
Check in each case whether the given function can serve as the probability distribution of an appropriate random variable. (a) f(x) = (2 x)/4 for x = 0, 1, 2; (b) f(x) = x - 2/9 for x = 1, 2, 3, 4, 5, 6; (c) f(x) = x^2 - 6x + 9/10 for x = 1, 2, 3, 4, 5; (d) f(x) = x^2 - 6x + 8/5 for x = 1, 2, 3, 4, 5.
def main():     # keeping asking user for a word or name until user enters 0    ...
def main():     # keeping asking user for a word or name until user enters 0     while True:         word = input('Enter a word/name to convert (enter 0 to quit): ').upper()       if word == '0': break         print(convert_to_soundex(word)) Whenever i try to run the program it tells me unintend doesn't match any outer identation level !!!!
How can I make a method to check out a customer given their name and booking...
How can I make a method to check out a customer given their name and booking number in Java. I have provided the Book class as well as the customer class. I have done the method to add a customer into the array however im failng to implement a method that checks out the customer. If you need more classes associated with the system please let me know ASAP and I will provide them, ----------------------------------------------------------------------------------------------------------------------------------- public class Book{    String...
4. A Corporation draws a check payable to First Bank. The check is given to an...
4. A Corporation draws a check payable to First Bank. The check is given to an officer of Corporation (known to Bank), who is instructed to deliver it to Bank in payment of a debt owed by Corporation to Bank. Instead, the officer, intending to defraud Corporation, delivers the check to Bank in payment of his personal debt. Bank has received funds of Corporation that have been used for the personal benefit of the officer. Corporation asserts a claim to...
Calculate this ANOVA by hand. Check your work by also calculating the ANOVA in SPSS or...
Calculate this ANOVA by hand. Check your work by also calculating the ANOVA in SPSS or EXCEL. Be sure to do any multiple comparison tests and interpret the results. Control GroupA1 PsychoanalysisA2 CBTA3 X1 7 7 3 X2 10 5 3 X3 6 6 2 X4 8 5 3 X5 10 5 4 X6 10 6 2 X barA1 SX (A1) SX2 SST = SX2 – T2/an                            (also called [X] – [T]) SST =                                                  (a = number...
(JAVA) We will write a program to check the spelling of the word entered by user,...
(JAVA) We will write a program to check the spelling of the word entered by user, using data from a dictionary, which is text file. The program will ask user to enter a word for spell check, and then check in the text file (dictionary.txt) if the word exists. (The dictionary.txt file is provided) If the word exists in text file, the output will be “Word is correctly spelled”. If the word doesn’t exist in the text file, program will...
hi please answer it by computer not a hand wtiting and by your own word I...
hi please answer it by computer not a hand wtiting and by your own word I have a project about psychological health , so I need a help to do this : Post communication strategies Post action and evaluation plans
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT