Answer to Question #301656 in Python for Sudheer

Question #301656

write a python function that accepts the value of two integers a and b and produces the output as (a+b)/(a-b). As he is still a kid, hence might not be able to enter the values correctly. Write a python function Divide_Op(a,b) (Refer RollNo_W10A_3.py) which produces the appropriate output or error message by handling all possible exceptions.

1
Expert's answer
2022-02-23T07:32:39-0500

def Divide_Op(a,b):

  if (a-b) == 0:

    print("can not divide a number by zero")

  else:

   answer = (a+b)/(a-b)

   return answer

num1 = int(input("Enter first number: "))

num2 = int(input("Enter second number: "))

output = Divide_Op(num1,num2)

print("(",num1,"+",num2,")/(",num1,"-",num2,") = ", output)


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