Your younger brother is studying in school. His computer teacher gives homework to make a calculator for six operations: addition, subtraction, multiplication, division, power, and modulo on two integers. As you are about to become an engineer, so he expected help from your side to develop the program. Therefore, write Calc.py module that define a separate function for implementing all the above-mentioned operations. Then import Calc.py in your RollNo_W12A_1.py file. In RollNo_W12A_1.py, define a function Arithmatic(a, b, op) which calls the respected function defined in Calc.py to perform the required operation. Also handle the possible exceptions and display the exception message in form of string
def Arithmatic(x,y,op):
Result=0
if(op=='+'):
Result = x+y
print(x,"+",y,"=",Result)
if(op=='-'):
Result = x-y
print(x,"-",y,"=",Result)
if(op=='*'):
Result = x*y
print(x,"*",y,"=",Result)
if(op=='/'):
Result = x/y
print(x,"/",y,"=",round(Result,2))
if(op=='%'):
Result = x%y
print(x,"%",y,"=",Result)
print(Arithmatic(5, 3,'+'))
print(Arithmatic(5, 3,'-'))
print(Arithmatic(5, 3,'*'))
print(Arithmatic(5, 3,'/'))
print(Arithmatic(5, 3,'%'))
Comments
Leave a comment