addition

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 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
Karmehavannan

I am Mr S.Karmehavannan. Founder and CEO of this website. This website specially designed for the programming learners and very especially programming beginners, this website will gradually lead the learners to develop their programming skill.

View Comments

  • 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

Recent Posts

How to find reverse number using method in Java

How to find reverse number using method In this article, we will discuss the concept…

19 hours ago

C# inverted full pyramid star pattern

C# inverted full pyramid star pattern In this article, we will discuss the concept of…

3 weeks ago

C# Full Pyramid star pattern program

C# Full Pyramid star pattern program In this article, we will discuss the concept of…

1 month ago

Program to count vowels,consonants,words, characters and space in Java

Program to count vowels, consonants, words, characters and space in Java In this article, we…

1 month ago

How to print multiplication table using Array in C++ language

How to print multiplication table using Array in C++ language In this post, we will…

1 month ago

C Program to multiplication table using Array

C Program to multiplication table using Array In this tutorial , we will discuss about…

2 months ago