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

Answered step by step
Verified Expert Solution
Question
86 users unlocked this solution today!

PYTHON

COMP SCI

image text in transcribed

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 list

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Link Copied!

Step: 1

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

100% Satisfaction Guaranteed-or Get a Refund!

Step: 2Unlock detailed examples and clear explanations to master concepts

blur-text-image_2

Step: 3Unlock to practice, ask and learn with real-world examples

blur-text-image_3

See step-by-step solutions with expert insights and AI powered tools for academic success

  • tick Icon Access 30 Million+ textbook solutions.
  • tick Icon Ask unlimited questions from AI Tutors.
  • tick Icon Order free textbooks.
  • tick Icon 100% Satisfaction Guaranteed-or Get a Refund!

Claim Your Hoodie Now!

Recommended Textbook for

More Books
flashcard-anime

Study Smart with AI Flashcards

Access a vast library of flashcards, create your own, and experience a game-changing transformation in how you learn and retain knowledge

Explore Flashcards

Students Have Also Explored These Related Databases Questions!