Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Need urgent help please **updated** pass return ret_fun def repeater(fun, num_repeats): n Returns a new function ret_fun. ret_fun should take a single input i, and

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedNeed urgent help please **updated**image text in transcribedimage text in transcribed

pass return ret_fun def repeater(fun, num_repeats): n Returns a new function ret_fun. ret_fun should take a single input i, and return fun applied to i num_repeats times. In other words, if num_repeats is 1 , ret_fun should return fun(i). If num_repeats is 2 , ret_fun should return fun(fun(i)). If num_repeats is , ret_fun should return i. :param fun: function : param num_repeats: int :return ret_fun: function " def ret_fun (x) : \# Fil1 in pass. return ret_fun if __ name == "_main '" def test1 (x) : return x2 def test2(x): return x3 data =[1,3,5,7,9,9,11,13,15,17,19] \# Testing the add_map function print(add_map(test1, data)) \#Calling the add_map function with function test1 and the \# Testing the compose_map function print(compose_map(test1, test2, data)) \# Calling the compose_map function with function \# Testing the add_map function print(add_map(test1, data)) \# Calling the add_map function with function test1 and the list data as the argument \# Testing the compose_map function print(compose_map(test1, test2, data)) \#Calling the compose_map function with functions test1, testz and the list data as the argument \# Using the compose function with functions test1 and test2 as arguments and returning its value to f1 f1= compose(test 1, test 2) \# Running f1 with i=4 print (f1(4)) \# Applying f1 on to each value in the list data print(list(map(f1, data))) \# Using the compose function with functions test2 and test1 as arguments and returning its value to f2 f2= compose(test 2 , test 1 ) \# Running f2 with i=4 print(f2(4)) \# Applying f2 on to each value in the list data print(list (map(f2, data))) * Testing the repeater function that with the function testi with different num_repeats argument. z= repeater ( test 1,a) once = repeater ( test 1,1) twice = repeater ( test 1,2) thrice = repeater ( test1, 3) print("repeat a times: \{\} ". format (z(5))) print ("repeat I time: \{\}, format(once(5))) print("repeat 2 times: \{\} ". format(twice(5)) ) print ( repeat 3 times: \{\} ".format ( thrice (5))) Problem 1 will get you familiar with several ways to build and use higher order functions. In this problem, we ask you to fill in the code for a number of missing functions in 1. : This takes in a function, fun, and a list, as its arguments and returns a list, which consists of applying then adding 1 to each element of the input list, 2. : This takes in two functions, and and a list, as its arguments and returns a list, which consists of applying then to each element of the input list, L. Note that you must apply the functions in that order: call first, then on the output of for each element in the input list 3. : This takes in two functions, and . and returns a new function, The function takes in a single argument, i, then calls followed by on that argument, returning the result. Note again that the order matters. Expected return type for is a function and not a value. 4. repeater: This takes in a function, and an integer, . The new function takes in an input x and calls on it times (in other words, you call on the output of calling on the output of calling ... on the input, repeated as many times as Expected return type for is a function and not a value. Testing If your code works, and you run the test code provided in problem1.py, you should get the following output: [3,7,11,15,17,17,23,27,31,35,39] [1,3,7,11,21,21,19,23,27,31,35] [4,0,4,8,24,24,16,20,24,28,32] 2 [4,0,4,8,24,24,16,20,24,28,32] 5 [1,3,7,11,21,21,19,23,27,31,35] repeat 0 times: 5 repeat 1 time: 10 repeat 2 times: 20 repeat 3 times: 40

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_2

Step: 3

blur-text-image_3

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

Select Healthcare Classification Systems And Databases

Authors: Katherine S. Rowell, Ann Cutrell

1st Edition

0615909760, 978-0615909769

More Books

Students also viewed these Databases questions

Question

c. Acafeteriawhere healthy, nutritionally balanced foods are served

Answered: 1 week ago