Lesson 6
Dealing with Sequences of Objects
Chapter 5: Applied problem solving
Smallest number divisible by 7
Next challenge! Write a function compute_min_divisible()
that takes two input arguments: a list of integers numbers
and an integer divisor
. The function should return the smallest of these integers that is divisible by the given divisor
. If none of the integers in the list are divisible by the given divisor
, then return None
.
You may use any built-in Python functions for this challenge, if needed. This includes min()
. You can actually pass a list to min()
as an input argument, for example min([4, 7, 6])
.
You can also use the sorted()
function to return a sorted list. For example, sorted([5, 2, 3, 6])
will return a new list [2, 3, 5, 6]
.
As usual, test your functions by writing test cases!
Sample inputs and outputs
Example 1
- Sample function call:
compute_min_divisible([66, 33, -55, 11], 11)
- Returns:
-55
Example 2
- Sample function call:
compute_min_divisible([7, 21, 11, 5, 2, 14], 7)
- Returns:
7
Example 3
- Sample function call:
compute_min_divisible([34, 5, 10, 19, 28, 74], 3)
- Returns:
None
Example 4
- Sample function call:
compute_min_divisible([], 4)
- Returns:
None