program that reads two numbers and an arithmetic operator and displays the computed result.
num1=float(input("Enter first number:"))
num2=float(input("Enter second number:"))
op=input("Enter operator[ + - * / % ]:")
result=0
If op == '+':
result=num1+num2
else op =='-':
result=num1-num2
else op =='*':
result=num1*num2
else op =='/':
result=num1/num2
else op =='%':
result=num1%num2
else:
print ("Invalid operator!!")
print(num1,op,num2,'=',result)
Output
Enter first number:5
Enter second number:2
Enter operator[ + - * / % ]: *
5.0*2.0=10.0
Comments
Post a Comment