Answered step by step
Verified Expert Solution
Link Copied!

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

image text in transcribed

image text in transcribedimage text in transcribed

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

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

Database Administrator Limited Edition

Authors: Martif Way

1st Edition

B0CGG89N8Z

More Books

Students also viewed these Databases questions

Question

Discuss three types of individual incentives.

Answered: 1 week ago

Question

In an Excel Pivot Table, how is a Fact/Measure Column repeated?

Answered: 1 week ago