Define a procedure clip(lo, x, hi)
that returns lo if x is less than lo, returns hi if x is greater than hi, and returns x otherwise. You can assume that lo < hi
.
This time, don’t use if, but use min
and max
. Your function should have type (num, num, num) -> num
.
import math
def clip(lo, x, hi):
return max(lo, min(x, hi))