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

Try your Solution

Strongly recommended to Solve it on your own, Don't directly go to the solution given below.

#write your code here

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

Comments