How do I define a piecewise function with functional restrictions? [closed]

asked 2019-12-17 15:30:25 +0200

mattiav gravatar image

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?

edit retag flag offensive reopen merge delete

Closed for the following reason duplicate question by tmonteil
close date 2019-12-17 21:26:48.034690