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

 

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

PHP Star Triangle pattern program

PHP Star Triangle pattern program In this tutorial, we will discuss about PHP Star Triangle…

2 months ago

PHP Full Pyramid pattern program

PHP Full Pyramid pattern program In this tutorial, we will discuss about PHP Full Pyramid…

2 months ago

5 methods to add two numbers in Java

5 methods to add two numbers in Java In this tutorial, we will discuss the…

2 months ago

Python Full Pyramid star pattern program

Python full Pyramid star pattern program In this tutorial, we will discuss  the concept of…

5 months ago

Write a function or method to convert C into F -Entered by user

Write a function or method to convert C into F -Entered by the user In…

10 months ago

How to write a function or method to convert Celsius into Fahrenheit

How to write a function or method to convert Celsius into Fahrenheit In this tutorial,…

10 months ago