Question | Less Than Counters
Write the function countfactors, then the function countprimes. Can you generalize the logic of the counting computation?
def count_factors(n):
"""
Return the number of positive factors n or smaller
>>> count_factors(2)
2
>>> count_factors(4)
3
>>> count_factors(12)
6
"""
## YOUR CODE HERE ##
def count_primes(n):
"""
Return the number of primes n or smaller
>>> count_primes(2)
1
>>> count_primes(3)
2
>>> count_primes(4)
2
>>> count_primes(5)
3
>>> count_primes(10)
4
>>> count_primes(20)
8
>>> count_primes(30)
10
"""
## YOUR CODE HERE ##
def count_cond(condition):
"""
Return a one-argument function that counts
the numbers less than that argument that
fulfills the condition
"""
## YOUR CODE HERE ##
count_primes_new = count_cond(___________)
count_factors_new = count_cond(___________)