- On
- By
- 4 Comments
- Categories: addition, multiply
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
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
4 Comments
sharath rajaboina February 9, 2020 at 7:30 pm
for multiple numbers how can we write loop
Muhammad Bashir July 3, 2023 at 11:56 am
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
Muhammad Bashir July 3, 2023 at 11:57 am
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
Muhammad Bashir July 3, 2023 at 12:00 pm
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