Decode School

Decode School - The School for Problem Solvers

Welcome to my blog. Subscribe and get my latest blog post in your inbox.

Calculator in python

Python Program to get a binary arithmetic expression and solve the expression.

Sample Input 1:

12 + 9

Sample Output 1:

21

Sample Input 2:

4 * 5

Sample Output 2:

20

Program or Solution

					    
							
num1=int(input("Enter first Number:"))
op=input("Enter Operation:")
num2=int(input("Enter Second Number:"))
if op=='+':
    result=num1+num2
elif op=='-':
    result=num1-num2
elif op=='*':
    result=num1*num2
elif op=='/':
    result=num1/num2
elif op=='%':
    result=num1%num2
else:
    result="invalid operation"
print(result)

					    
					

Program Explanation

Based on the second input (operator) any one arthmetic operation in chained if will be done