Program that reads two numbers and an arithmetic operator and displays the computed result. (python)
Answers
num1= float (input("Enter first number:"))
num2=float (input("Enter second number:"))
op=input("enter operator [+-*/%])
result=0
if op=='+':
result=num1+num2
elif op =='-':
result=num1-num2
elif op=='*':
result=num1*num2
elif op=='/':
result=num1/num2
else:
print("Invalid operator!!")
print(num1,op,num2,'=',result)
Here you go:
num1= int(input("Enter first number:"))
num2= int(input("Enter second number:"))
op=input("enter operator: ")
result=0
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
elif op=='**':
result=num1**num2
elif op=='//':
result=num1//num2
else:
print("Invalid operator!!")
print(num1,op,num2,'=',result)
Explanation: