Question: answer the answer in python and please use good penmenship TY in advance This is a programming problem. Create a new Python file named p2.py


answer the answer in python and please use good penmenship TY in advance
This is a programming problem. Create a new Python file named p2.py and write the solution in it. When done, upload the file by clicking on the button below. Make sure your code works, follows strictly all requirements, and complies with the Python coding style taught in class. Do not change the signature (name, parameter list) of any function, if given. Don't worry if Canvas changes the file name after you upload it. Pay attention to details. a) Write a generator every_nth(seq, n) that yields a sequence with every nth element from the sequence seq, starting with the first element. Example: expression every_nth(range(0, 20), 3) returns a sequence with every third elements in range(0,20) Thus this program: for x in every nthCrange(0, 20), 3): print(x, end-",") prints 0, 3, 6, 9, 12, 15, 18, b) Write a generator accumulate(seq, fun, val0) that returns the sequence of the values constituting the successive accumulation of elements starting with val0 (the initial value), using the given binary function fun for accumulation. For illustration, accumulate ([a,b,c], f, val0), for some function f and initial value valo should return sequence val0, f(val0,a), f(f(val0,a), b), f(f(f(val0,a), b), c). For example, expression accumulate(range (1,6), lambda x.y:x+y, 0) yields sequence 0, 1, 3, 6, 10, 15 since range(1,6) yields sequence 1, 2, 3, 4, 5, actual argument valO is 0 and the accumulation function is simple addition
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
