Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

help with this code please, with explanations if you can. thank you! 2. Write a function scrabble_score(word) that takes as input a string word containing

image text in transcribedhelp with this code please, with explanations if you can. thank you!

2. Write a function scrabble_score(word) that takes as input a string word containing only lowercase letters, and that uses recursion to compute and return the scrabble score of that string - i.e., the sum of the scrabble scores of its letters. For example: In addition to calling itself recursively, the function must also call your letter_score function to determine the score of a given letter. Doing so will allow you to avoid repeating the long if-elif-else statement that is already present in letter_score. Indeed, the only if-else statement that you should need is the one that determines whether you have a base case or recursive case. 3. Write a function BUtify(s) that takes as input an arbitrary string s and uses recursion to determine and return a new string in which all lower-case bs are replaced by upper-case Bs and all lower-case us are replaced by upper-case Us. For example: >> BUtify('you be you') result: 'you Be you' > BUtify('beautiful') result: 'BeaUtiful' > BUtify ('unbelievable') result: 'UnBelievaBle' 4. Write a function diff(vals1, vals 2 ) that takes as inputs two arbitrary lists of non-negative integers vals1 and vals2 and uses recursion to construct and return a new list in which each element is the the absolute value of the difference of the corresponding elements from the original lists. For example: diff([3,4,2,5],[7,2,9,5]) result: [4,2,7,0] In the return value for this case: - The first element is 4 , because the difference of the first elements in the original lists is 37=4, and we multiply by 1 to get the absolute value. - The second element is 2 , because the difference of the second elements in the original lists is 42=2, and we don't need to adjust it because 2 is already non-negative. - The third element is 7 , because 29=7, and we multiply by 1 to get the absolute value. - The fourth element is , because 55=0. Important You may not use Python's built-in function for computing the absolute value of a number. Rather, you will need to use conditional execution to determine whether you need to adjust the result of subtracting a given pair of elements. Here are two other examples: If one of the lists is longer than the other, its "extra" elements - the ones with no counterparts in the shorter list - should appear immediately after the differences (if any) in the returned list. For example

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

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

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Graph Databases New Opportunities For Connected Data

Authors: Ian Robinson, Jim Webber, Emil Eifrem

2nd Edition

1491930896, 978-1491930892

More Books

Students also viewed these Databases questions

Question

Find Io in the circuit of Fig. 9.60. 4 Io 2 8 10 602-30 v

Answered: 1 week ago

Question

Define thenpopulation parameters in context

Answered: 1 week ago