lundi 16 septembre 2019

Python: conditional switch statement with addition operation

I am trying to define a switch/conditional statement that identifies if an addition operation of two scalar variables fits one of three scenarios namely increase, decrease and change/cross (negative to positive) e.g.

increase:

A = 5
B = 5
A + B = 10

A = -5
B = -5
A + B = -10

decrease:

A = 5
B = -2
A + B = 3

cross:

A = -5
   B = 10
   A + B = 5

I have tried implementing the logic in python as follows.

C = A + B
if (abs(0-C)<abs(B)):
   print("The addition of A and B is a CROSS type")
elif (abs(0-C)>abs(B)):
   print("The addition of A and B is an INCREASE type")
else:
   print("The addition of A and B is an DECREASE type")

Obviously this fails, I was hoping to get some advice on how I could best implement this. Your help here would be great, Thanks.

Aucun commentaire:

Enregistrer un commentaire