Write a largestBelowValue(numbers, value) function that returns the largest number in the list numbers that is smaller than value. Assume the numbers are always positive integers.
Some example test cases (include these test cases in your program):
>>>print(largestBelowValue([31, 5, 71, 53, 40, 17], 40))
31
>>>print(largestBelowValue([31, 5, 71, 53, 40, 17], 41))
40
returns None since no value is smaller than 2 in the list
>>>print(largestBelowValue([31, 5, 71, 53, 40, 17], 2))
None
def largestBelowValue(numbers, value): largestValue = None for n in numbers: if n < value and (largestValue is None or n > largestValue): largestValue = n return largestValue
Get Answers For Free
Most questions answered within 1 hours.