-1

I want to print int in multi-line

Here is my python code:

a=int(3)
b=int(5)
c=a+b,"\n",a-b,"\n",a*b,"\n"
print(c)

Output I want to achieve:

 8
-2
 15

Output I'm getting:

(8, '\n', 2, '\n', 15, '\n')

Will someone help me out with this?

4 Answers4

1
a=3
b=3
c=str(a+b)+"\n" + str(a-b) + "\n" + str(a*b) + "\n"
print(c)

Try this one.

0

Try this:

c=str(a+b)+"\n" + str(a-b) + "\n" + str(a*b) + "\n"
intedgar
  • 631
  • 1
  • 11
0

You could iteratively print the elements of c.

a = int(3)
b = int(5)
c = a+b, a-b, a*b

for i in c:
    print(i)
Bashton
  • 339
  • 1
  • 11
0

when writing : c = a+b,"\n",a-b,"\n",a*b,"\n" you actually creating a tuple, separated by commas,

that's why when printing this is the output you get. this is why @Bashton answer require iterations on c (as a list)

if you with replace the commas with + you actually create one string concatenated (by + signs). that's why when you print it only takes one print. that's why

c=str(a+b)+"\n" + str(a-b) + "\n" + str(a*b) + "\n"

solution would only require one print.