All Arithmetic calculation (Addition, Subtraction, Multiplication, Division) using Python
- Now i am going to show you to find all arithmetic calculation at once with user value using python.
- Lets start with explanation and example program.
Aim
- To create arithmetic calculation program using python.
Procedure
- Open Python IDLE setup and create new file and save as arithmetic.py
- Get two values from the user using input()-function.
- And do the arithmetic calculation (Addition, Subtraction, Multiplication, Division), sum=a+b, sub=a-b, mul=a*b, div=a/b.
- Print the value using print()- function.
- Run the program using F5.
Explain with Program
// Arithmetic Calculation //
a=int(input("Enter First Value:"))
b=int(input("Enter Second Value:"))
sum=a+b
sub=a-b
mul=a*b
div=a/b
print("First Number:",a)
print("Second Number:",b)
print("Arithmetic calculation at once")
print("Addition :",a,"+",b,"=",sum)
print("Subtraction :",a,"-",b,"=",sub)
print("Multiplication :",a,"*",b,"=",mul)
print("Division :",a,"/",b,"=",div)
Code with explanation
..............
a=int(input("Enter First Value:"))
b=int(input("Enter Second Value:"))
............
- Get value (a=?)from user.
- Get value (b=?)from user.
.................
sum=a+b
sub=a-b
mul=a*b
div=a/b
..............
- sum - addition of a and b.
- sub- subtraction of a and .
- mul- multiplication of a and b
- div-division of a and b.
.....................
print("First Number:",a)
print("Second Number:",b)
print("Arithmetic calculation at once")
print("Addition :",a,"+",b,"=",sum)
print("Subtraction :",a,"-",b,"=",sub)
print("Multiplication :",a,"*",b,"=",mul)
print("Division :",a,"/",b,"=",div)
...........................
- print function of a,b value.
- print addition.
- print subtraction.
- print multiplication.
- print division.
Output
Enter First Value: 10
Enter Second Value: 5
First Number:10
Second Number:5
Arithmetic calculation at once
Addition: 10+5 = 15
Subtraction: 10-5 = 5
Multiplication: 10*5 = 50
Division: 10/5 = 2
You may also check Python Tips
Also check HTML & JS