Answer to Question #308500 in Python for jsa

Question #308500

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


1
Expert's answer
2022-03-09T06:39:45-0500
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,'%'))

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS