I have a function that should return at least one output, and should return optional values depending on how I set the flag. For example:
def foo(a, b, f1=False, f2=False, f3=False):
c = a + b
if f1:
d = a - b
elif f2:
e = a * b
elif f3:
f = a / b
if f1:
return c, d
elif f2:
return c, e
elif f3:
return c, f
elif f1 and f2:
return c, d, e
elif f1 and f3:
return c, d, f
elif f2 and f3:
return c, e, f
elif f1 and f2 and f3:
return c, d, e, f
else:
return c
If I have f1, f2, ..., fn as inputs, I will need to write 2**n return. That can be too many. Is there a better way to handle it? The example code is corrected according to @Tim Roberts' comments.
list?f1 & f2. This is not C. In Python, you writef1 and f2. The two are NOT interchangeable.ifstatement to return different outputs