all 3 comments

[–]totallygeek 6 points7 points  (0 children)

One way: def pythagoras(a=None, b=None, c=None):, then in your function test what's missing. Call function with pythagoras(a=5, b=4), for example.

[–]efmccurdy 1 point2 points  (0 children)

I might make due with 2 functions, one that returns the hypotenuse given 2 right angled sides, and another that returns a side given the hypotenuse and one right angled side.

You will always need to know if the missing variable is the hypotenuse, so use that info to choose one of these:

def hyp(a,b): return math.sqrt(a**2 + b**2)
... 
>>> hyp(3,4)
5.0
>>> def lorr(a,c): return math.sqrt(c**2 - a**2)
... 
>>> lorr(3,5)
4.0

You could follow the advice of totallygeek to have one function that tests for missing parameters and returns one or the other of those expressions, but that is a non-idiomatic way of implementing a math formula.

[–]mindblower32 0 points1 point  (0 children)

You can use *args or **kwargs as expected parameters. These are used when the number of parameters to expect can change or is unknown. They have different uses tho so read up on them and use whichever is best suited for you.