Codeforcoding

Python program to Addition subtraction,multiplication ,division

Python program to Addition subtraction, multiplication, division

In this tutorial, we will discuss the Python program to Addition subtraction, multiplication, division

Python program to Addition
Python Program to Arithmetic operation

In this post, we will learn about how to perform addition, subtraction multiplication, division of any two numbers  using if else statements in Python programming

The  program will request the user to enter two number digits and the user select an operator to perform the addition, subtraction, multiplication, and division of the entered number by the user and displays the output on the screen
the program will display the result according to the user selection

 

Program 1

#Python program to perform Addition, Subtraction,
#Multiplication and division of two numbers

num1=int(input("Enter the first number: "))
num2=int(input("Enter the second number: "))

print("Enter the operator you want to perform");

ch=input("Enter any of these operator for operation +, -, *, /  ")

result=0
if ch=='+':
    result=num1+num2;
elif ch=='-':
    result=num1-num2;

elif ch=='*':
    result=num1*num2;
elif ch=='/':
    result=num1/num2;

else:
   print("char is not supported");

print(num1,ch,num2,": ",result)

When the above code is executed, it produces the following results

Case 1

Enter the first number: 12
Enter the second number: 3
Enter the operator you want to perform
Enter any of these operator for operation +, -, *, /  +
12 + 3 :  15

 

Case 2

Enter the first number: 35
Enter the second number: 25
Enter the operator you want to perform
Enter any of these operator for operation +, -, *, /  -
35 - 25 :  10

Case 3

Enter the first number: 12
Enter the second number: 4
Enter the operator you want to perform
Enter any of these operator for operation +, -, *, /  *
12 * 4 :  48

Case 4

Enter the first number: 55
Enter the second number: 5
Enter the operator you want to perform
Enter any of these operator for operation +, -, *, /  /
55 / 5 :  11.0

 

Related program in other languages

Cpp Add Subtract Multiply Divide

C Add Subtract Multiply Divide

Java Add, Subtract, Multiply, Divide

Addition of two numbers in Java language

Addition of two numbers in C  language using pointer

Addition of two numbers in C++ language using bitwise operator

Addition of two floating point numbers in C# language

Addition of two numbers in java using method

 

Suggested for you

Operator in Java language

If statements in Java language

Data type in Java language

 

Java code to Addition Subtraction,Multiplication and division
C program to add two numbers using pointer
Exit mobile version