In this python if else program, we will accept two numbers and mathematical operations from users and perform mathematical operations according to it.
Arithmetic operations in Maths:
Addition (Finding the Sum; ‘+’)
Subtraction (Finding the difference; ‘-‘)
Multiplication (Finding the product; ‘×’ )
Division (Finding the quotient; ‘÷’)
Steps to solve the program
- Take two numbers and a mathematical operation of your choice (+,-,*,/) as input.
- Using if-else statements perform the corresponding operations on numbers.
- Print the output.
num1 = int(input("Enter 1st number: "))
num2 = int(input("Enter 2nd number: "))
operation = input("Enter operation of your choice")
if operation == "+":
print(num1+num2)
elif operation == "-":
print(num1-num2)
elif operation == "/":
print(num1/num2)
elif operation == "*":
print(num1*num2)
else:
print("Invalid operation")
Output :
Enter 1st number: 30
Enter 2nd number: 45
Enter operation of your choice: +
75
Related Articles
Python program to accept marks from the user allot the stream based on the following criteria.
Python program to check given number is divided by 3 or not.
If else program to get all the numbers divided by 3 from 1 to 30.
If else program to assign grades as per total marks.
Python program to check the given number divided by 3 and 5.
Python program to print the square of the number if it is divided by 11.