There is an equation

a = 5 b = 6 print(a+b) #5+6 

How to do so if the variable b values ​​a negative -6, he placed it in parentheses

 print(a+b) #5+(-6) 
  • Are you about math or textual representation? - eri

1 answer 1

The simplest option is to add a condition:

 if b >= 0: print('%d + %d' % (a, b)) else: print('%d +(-%d)' % (a, b)) 

In your case 11 will be displayed, not 5 + 6.