Suppose, input is a and b.
and output will be like,
a + b = (summation of a and b)
a - b = (subtraction of a and b)
a * b = (multiplication of a and b)
a / b = (Division of a and b)
Note:i can use just one print function inside this program and normally i’ve to use \n to create newline.
If i write this in C then it;ll be like:
#include <stdio.h>
int main()
{
int a, b;
scanf("%d %d",&a,&b);
printf("a+b = %d\na-b = %d\na*b = %d\na/b = %d",a+b,a-b,a*b,a/b);
return 0;
}
And output is correct here:
5 2
a+b = 7
a-b = 3
a*b = 10
a/b = 2
Process returned 0 (0x0) execution time : 5.089 s
Press any key to continue.
Here,i can control every output by %d inside printf
function.But, how i’ll write this in python just using one print function.
i try it ,but failed.
My code in python:
a = input()
b = input()
a = int(a)
b = int(b)
print("a + b = %d\na - b = %d\na * b = %d\na / b =%d\n",a+b,a-b,a*b,a/b)
if i input 5 as a and 2 as b then,output look like,
C:\Users\Plabon kumer Sarker\Desktop\python 1st part>arithmeticex3.py
5
2
a + b = %d
a - b = %d
a * b = %d
a / b =%d
7 3 10 2.5
That means, %d
not work in python
But,How can i fix this?