Question: use question 1 to answer question 2 1. Write a function letter_score(letter) that takes a string of length 1 as input, and if the string

1. Write a function letter_score(letter) that takes a string of length 1 as input, and if the string is a lowercase letter from 'a' to 'z' the function returns the value of that letter as a scrabble tile. Otherwise the function returns 0 (to handle cases of uppercase letters or other characters such as '@'). This function does not require recursion. Here is the mapping of letters to scores that you should use: A B C D E F G H I J K L M N O P Q R S T U V W X Y Z For example: >>> letter_score('w') 4 >>> print(letter_score(',')) 10 >>> letter_score('%') # not a letter 0 >>> letter_score('A') # not lower-case 0 We encourage you to begin with the following template: *** HH def letter_score(letter): your docstring goes here assert(len(letter) 1) BE # put the rest of your function here Note that we begin with an assert statement that validates the input for the parameter c. If the condition given to assert is not true-in this case, if the input provided for c has a length other than 1-then assert will cause your code to crash with an AssertionError. Using assert in this way can help you to find and debug situations in which you accidentally pass in incorrect values for the parameter of a function. 2. Write a function scrabble score(word) that takes as input a string word', 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: >>> scrabble_score('python') 14 >>> scrabble_score('a') 1 >>> scrabble_score("quetzal') 25 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
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
