Question: def sum _ digits ( y ) : Return the sum of the digits of non - negative integer y .

def sum_digits(y):
"""Return the sum of the digits of non-negative integer y."""
total =0
while y >0:
total, y = total + y %10, y //10
return total
def is_prime(n):
"""Return whether positive integer n is prime."""
if n ==1:
return False
k =2
while k < n:
if n % k ==0:
return False
k +=1
return True
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, where
the first argument for Condition is N and the second argument is the
number from 1 to N.
>>> count_fives = count_cond(lambda n, i: sum_digits(n * i)==5)
>>> count_fives(10) # 50(10*5)
1
>>> count_fives(50) # 50(50*1),500(50*10),1400(50*28),2300(50*46)
4
>>> is_i_prime = lambda n, i: is_prime(i) # need to pass 2-argument function into count_cond
>>> count_primes = count_cond(is_i_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
8
"""
"*** YOUR CODE HERE ***"

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!