# lab04.py - Question 1 roundtothis = 10 def...

• Lab Report
• 3

This preview shows page 1 - 3 out of 3 pages.

# Question 1 roundtothis = 10 def data_clean(a): """Write a function that rounds each element of the list down to the nearest tens place. >>> a = [12, 23, 34] >>> data_clean(a) [10, 20, 30] >>> b = [238, 193, 928] >>> data_clean(b) [230, 190, 920] >>> c = [10, 20, 30] >>> data_clean(c) [10, 20, 30] >>> d = [9, 9, 9] >>> data_clean(d) [0, 0, 0] """ #return [] #map(funct,[] ) #return def helper (a): if (a % roundtothis == 0 and a != 0 ): return a else: return a - a %10 return list(map(helper, a)) # Question 2 from operator import add, mul def reduce(reducer, s, base): """Reduce a sequence under a two-argument function starting from a base value. >>> def add(x, y): ... return x + y >>> def mul(x, y): ... return x*y >>> reduce(add, [1,2,3,4], 0) 10 >>> reduce(mul, [1,2,3,4], 0) 0 >>> reduce(mul, [1,2,3,4], 1) 24 """ for x in s: first_reducer = reducer(x,base) base= first_reducer return base # Question 3 def piecewise(f, g, b): """Returns the piecewise function h where: h(x) = f(x) if x < b,

Subscribe to view the full document.

g(x) otherwise >>> def negate(x): ... return -x >>> def identity(x): ... return x
• Fall '18
• Continuous function, The Return, Carriage return, return list

{[ snackBarMessage ]}

###### "Before using Course Hero my grade was at 78%. By the end of the semester my grade was at 90%. I could not have done it without all the class material I found."
— Christopher R., University of Rhode Island '15, Course Hero Intern

### What students are saying

• As a current student on this bumpy collegiate pathway, I stumbled upon Course Hero, where I can find study resources for nearly all my courses, get online help from tutors 24/7, and even share my old projects, papers, and lecture notes with other students.

Kiran Temple University Fox School of Business ‘17, Course Hero Intern

• I cannot even describe how much Course Hero helped me this summer. It’s truly become something I can always rely on and help me. In the end, I was not only able to survive summer classes, but I was able to thrive thanks to Course Hero.

Dana University of Pennsylvania ‘17, Course Hero Intern

• The ability to access any university’s resources through Course Hero proved invaluable in my case. I was behind on Tulane coursework and actually used UCLA’s materials to help me move forward and get everything together on time.

Jill Tulane University ‘16, Course Hero Intern