Ad

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