Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

How do I define a piecewise function with functional restrictions?

I have to define a piecewise function T(x,y) which equals xy if xy>0 and x+y for x*y<=0. How do I do this? I have tried in this way:

def T(x,y):
  if (x>0):
    return x*y
  else:
    return x+y

but it does not work. How can I solve this problem?