Python Forum

Full Version: I give up...Please help.
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Hi fellows.

I just started to learn python but I am stuck with this problem.

I have to create a function:

def clip(lo, x, hi).

The function takes in three numbers and returns a value based on the value of x. Returns:
-lo, when x < lo
-hi, whtn x > hi
-x, otherwise.

The problem for me is that we do not have to use -for this problem- any conditional statements. Instead, we have to use the built in python functions min() and max().

I do not know how to do it....yet.

thanks!

high_existence
use if, elif and else statements like so:
if x < lo:
    return lo
elif x > hi:
    return hi
else:
    return x
also helps to put in your code so we can it as a whole also do you want it to return it or print it? Just want to make sure since you said you are just learning python.
question asked & answered like 5 years ago...

https://stackoverflow.com/questions/1491...-statement
Thanks so much ka06059. That was a great help!.
Beleive me metulburr, I tried.
See you!...or may be not.
bye
But you never posted any code so how would we know?