Question: PYTHON 3 Take a look at this function: def div(k): return 42 % k == 0 This function takes as input an integer k and
PYTHON 3
Take a look at this function:
def div(k): return 42 % k == 0
This function takes as input an integer k and then returns the result of evaluating the expression
42 % k == 0
The left-hand side of that expression computes the remainder when 42 is divided by k. (k need not be an integer, but then computing the remainder modulo k is a bit weird!) Next, that remainder is tested to see if it is equal to 0. The result is a boolean value - either True or False.
Next, take a look at this Python function called divides:
def divides(n) def div(k): return n % k == 0 return div
Write a function called prime(n) that takes a positive integer n as input and returns True or False depending on whether n is prime or composite. [Hint: you should NOT use any loop structures or recursion here. Instead, you may use map and call the divides function above, and you may wish to use sum which takes a list of numbers as input and returns the sum of the numbers in that list. ]
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
