Python Forum
I give up...Please help.
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
I give up...Please help.
#1
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
Reply
#2
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.
Reply
#3
question asked & answered like 5 years ago...

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


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020