lab02_extra.py - \"Optional program for lab02 from lab02 import def count_cond(condition\"Returns a function with one parameter N that counts all the

# lab02_extra.py - "Optional program for lab02 from lab02...

• Lab Report
• 1
• 50% (2) 1 out of 2 people found this document helpful

This preview shows page 1 out of 1 page.

"""Optional program for lab02 """ from lab02 import * def count_cond(condition): """Returns a function with one parameter N that counts all the numbers from 1 to N that satisfy the two-argument predicate function CONDITION. >>> count_factors = count_cond(lambda n, i: n % i == 0) >>> count_factors(2) # 1, 2 2 >>> count_factors(4) # 1, 2, 4 3 >>> count_factors(12) # 1, 2, 3, 4, 6, 12 6 >>> is_prime = lambda n, i: count_factors(i) == 2 >>> count_primes = count_cond(is_prime) >>> count_primes(2) # 2 1 >>> count_primes(3) # 2, 3 2 >>> count_primes(4) # 2, 3 2 >>> count_primes(5) # 2, 3, 5 3 >>> count_primes(20) # 2, 3, 5, 7, 11, 13, 17, 19

#### You've reached the end of your free preview.

Want to read the whole page?

• Fall '09
• def, two-argument predicate function

### 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