In this tutorial, we will discuss the Python program to Addition subtraction, multiplication, division
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
If statements in Java language
How to find reverse number using method In this article, we will discuss the concept…
C# inverted full pyramid star pattern In this article, we will discuss the concept of…
C# Full Pyramid star pattern program In this article, we will discuss the concept of…
Program to count vowels, consonants, words, characters and space in Java In this article, we…
How to print multiplication table using Array in C++ language In this post, we will…
C Program to multiplication table using Array In this tutorial , we will discuss about…
View Comments
for multiple numbers how can we write loop
I want to add Various numbers like 8+32+42*5/6-3-6-4 which means 8,32 and 42 are added first then this total is multiplied by 5 the result is devided by 6 and finally the figures 3,6 and 4 substracted.
how to make loop and get the result in Python
I want to add Various numbers like 8+32+42*5/6-3-6-4 which means 8,32 and 42 are added first then this total is multiplied by 5 the result is divided by 6 and finally the figures 3,6 and 4 substracted.
how to make loop and get the result in Python
I want to add Various numbers like 8+32+42*5/6-3-6-4
how to make loop and get the result in Python