Problem:
Write a Python function, clip(lo, x, hi) that returns lo if x is less than lo; hi if x is greater than hi; and x otherwise. For this problem, you can assume that lo < hi.
Don't use any conditional statements for this problem. Instead, use the built in Python functions min and max. You may wish to read the documentation on min and the documentation on max, and play around with these functions a bit in your interpreter, before beginning this problem.
This function takes in three numbers and returns a single number.
Code Given:
def clip(lo, x, hi):'''Takes in three numbers and returns a value based on the value of x.Returns:- lo, when x < lo- hi, when x > hi- x, otherwise'''
My Code Added:
def clip(lo, x, hi):'''Takes in three numbers and returns a value based on the value of x.Returns:- lo, when x < lo- hi, when x > hi- x, otherwise'''if min(x, lo, hi) == x:return loelif max(x, lo, hi) == x:return hielse:return x
Here's the problem: I can't use ANY conditionals. Help!