Accept two numbers and mathematical operations from users

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
  1. Take two numbers and a mathematical operation of your choice (+,-,*,/) as input.
  2. Using if-else statements perform the corresponding operations on numbers.
  3. 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

accept the temperature in Fahrenheit and check whether the water is boiling or not.

accept marks from the user allot the stream

Leave a Comment