Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Here are the descriptions of the functions: 1. Write a function process(vals) that takes as input a list of numbers vals and uses recursion to
Here are the descriptions of the functions: 1. Write a function process(vals) that takes as input a list of numbers vals and uses recursion to compute and return the sum of the squares of the individual numbers in the list. For example: process([2, 5, 3]) should recursively compute 2*2 + 5*5 + 3*3 and return the resulting value of 38. Here are two more examples: >>> process([1, 2, 3, 4]) result: 30 >>> process([6, 8]) result: 100 If the list is empty, the function should return 0: >>> process()) result: 0 This function is somewhat similar to the the mylen function from lecture, but it needs to deal with lists instead of strings. You can find a modified version of mylen that handles both strings and lists here. 2. Write a function count_spaces(s) that takes an arbitrary string input s and uses recursion to determine and return the number of spaces in s. For example: >>> count_spaces ('fee fi fo fum') result: 3 >>> count_spaces('hello world') result: 1 >>> count_spaces('howdy'). result: 0 This function is similar to the num_vowels function from lecture. 3. Write a function copy(s, n) that takes a string s and an integer n, and that uses recursion to create and return a string in which n copies of s have been concatenated together. To force you to use recursion, you may not use the multiplication operator (*). Rather, you should use recursion to add together n copies of s. For example, 'hello'*3 is equivalent to 'hello'+'hello'+'hello', and you will need to use recursion to compute that sum. If n is less than or equal to 0, the function should return the empty string (i.e., the string '', which does not have any spaces between the quotes). Here are some test cases: >>> copy('da', 2) result: 'dada' >>> copy('GO BU!', 4) result: 'Go BU!GO BU!GO BU!GO BU!' >>> copy('hello', 1) result: 'hello' >>> copy('hello', 0) result
Step 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