Question: 3. Write a function num_consonants (s) that takes as input a string s and returns the number of consonants in s. For example: >>> num_consonants


3. Write a function num_consonants (s) that takes as input a string s and returns the number of consonants in s. For example: >>> num_consonants ('computer') result: 5 Here again, you may assume that the string s contains only lowercase letters. We strongly encourage you to use as a helper function one of the functions that you wrote for parts 1 and 2 of this problem. Think about how you could use the value returned by one of those functions to determine how many consonants are in a given word. If you prefer, you may have num_consonants use either recursion or a list comprehension, rather than calling one of your functions from parts 1 and 2. However, you will end up with a much shorter and simpler function if you take advantage of one of your functions from parts 1 and 2! 4. Write a function called most_consonants (wordlist) that takes a list of lowercase words called wordlist and returns the word in the list with the most consonants. For example: >>> most_consonants(['computer', 'science']) result: computer' >>> most_consonants(['obama', 'bush', 'clinton']) result: 'clinton' You don't need to worry about cases in which two or more words are tied for the most consonants. The function that you write must use your num_consonants function from part 3 as a helper function. We also strongly encourage you to use the list-of-lists technique that we discussed in lecture as the basis of your most_consonants function, but you may use recursion instead if you prefer. 5. Write a function called num_multiples (m, values) that takes an integer m and a list of integers values and returns the number of integers in values that are multiples of m. For example: # 2 of the values (15 and 10) are multiples of 5 >>> num_multiples (5, [2, 15, 10]) result: 2 >>> num_multiples (3, [12, 3, 6, 7, 9]) # 12, 3, 6 and 9 are multiples of 3 result: 4 # only 18 is a multiple of 9 >>> num_multiples (9, [15, 18]) result: 1 We encourage you to use a list comprehension in this problem, but you may use recursion instead if your prefer. Hint: If you use a list comprehension, you should include an if clause in the list comprehension. In addition, you should consider how you could use one of the built-in Python functions that we have discussed in lecture to process the results of the list comprehension
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
