example: cap(0, 10, 11) => 10
11 is greater than 10, therefore it caps to 10
example: cap(5, 10, 1) => 5
1 is less than 5, therefore it caps to 5
example: cap(0, 10, 5) => 5
5 is within 0 < x < 10, therefore it returns the number
def cap(low, high, num):
if num < low: return low
elif num > high: return high
else: return num
import codewars_test as test
from solution import cap
@test.describe("Basic")
def test_group():
@test.it("1")
def _():
test.assert_equals(cap(0, 5, 4), 4)
@test.it("2")
def _():
test.assert_equals(cap(3, 5, 2), 3)
@test.it("3")
def _():
test.assert_equals(cap(3, 5, 9), 5)