Answered step by step
Verified Expert Solution
Question
1 Approved Answer
PYTHON COMP SCI PROBLEM 1 Implement wordsWithScoreO which is specified below. Hints:Use map. Feel free to use some of the functions you did for homework
PYTHON
COMP SCI
PROBLEM 1 Implement wordsWithScoreO which is specified below. Hints:Use map. Feel free to use some of the functions you did for homework 2 (Scrabble Scoring). As always, include any helper functions in this file, so we can test it def wordsWithScore(dct, scores): "List of words in dct, with their Scrabble score. Assume dct is a list of words and scores is a list of [Letter,number] pairs. Return the dictionary annotated so each word is paired with its value. For example, wordsWithScore(Dictionary, scrabbleScores) should return C'a', 1], C'am', 4], C'at', 2] ...etc... ] return None # your code goes here Just knowing the minimum number of coins is not as useful as getting the actual list of coins. Next, write another version of the change function called giveChange that takes the same kind of input as change but returns a list whose first item is the minimum number of coins and whose second item is a list of the coins in that optimal solution. Here's an example: >>>giveChange (48, [1, 5, 10, 25, 50]) [6, [25, 10, 10, 1, 1, 11 >>>giveChange (48, [1, 7, 24, 42]) 2, [24, 24]] >>>giveChange (35, [1, 3, 16, 30, 50]) [3, [16, 16, 3]] The order in which the coins are presented in the input list doesn't really matter and, similarly, the order in which your solution reports the coins to use is also unimportant: In other words the solution [3, [16, 16, 31] is the same to us as [3, [3, 16, 16] or [3, [16, 3, 16]]. All of these solutions use the same 3 coins after all! This problem may seem challenging at first, but keep in mind that once you establish that giveChange will always return a list of the formnumberofCoins, listofCoins], you can modify your change function relatively modesly to get the giveChange function. First, your base cases must observe the convention and return such a list of the form [numberOfcoins, listofcoins] Then, when you call giveChange recursively, remember that it is returning a list of this form. Your function will need to pick apart that list to get at the number of coins and the list of coins in that solution Finally, after deciding whether the use-it or lose-it solution is better, you can prepare your list of the form numberofCoins, listofCoins] and retum that list. PROBLEM 1 Implement wordsWithScoreO which is specified below. Hints:Use map. Feel free to use some of the functions you did for homework 2 (Scrabble Scoring). As always, include any helper functions in this file, so we can test it def wordsWithScore(dct, scores): "List of words in dct, with their Scrabble score. Assume dct is a list of words and scores is a list of [Letter,number] pairs. Return the dictionary annotated so each word is paired with its value. For example, wordsWithScore(Dictionary, scrabbleScores) should return C'a', 1], C'am', 4], C'at', 2] ...etc... ] return None # your code goes here Just knowing the minimum number of coins is not as useful as getting the actual list of coins. Next, write another version of the change function called giveChange that takes the same kind of input as change but returns a list whose first item is the minimum number of coins and whose second item is a list of the coins in that optimal solution. Here's an example: >>>giveChange (48, [1, 5, 10, 25, 50]) [6, [25, 10, 10, 1, 1, 11 >>>giveChange (48, [1, 7, 24, 42]) 2, [24, 24]] >>>giveChange (35, [1, 3, 16, 30, 50]) [3, [16, 16, 3]] The order in which the coins are presented in the input list doesn't really matter and, similarly, the order in which your solution reports the coins to use is also unimportant: In other words the solution [3, [16, 16, 31] is the same to us as [3, [3, 16, 16] or [3, [16, 3, 16]]. All of these solutions use the same 3 coins after all! This problem may seem challenging at first, but keep in mind that once you establish that giveChange will always return a list of the formnumberofCoins, listofCoins], you can modify your change function relatively modesly to get the giveChange function. First, your base cases must observe the convention and return such a list of the form [numberOfcoins, listofcoins] Then, when you call giveChange recursively, remember that it is returning a list of this form. Your function will need to pick apart that list to get at the number of coins and the list of coins in that solution Finally, after deciding whether the use-it or lose-it solution is better, you can prepare your list of the form numberofCoins, listofCoins] and retum that listStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started