+ 1
Write a function which would divide two numbers, design the function in a manner that it handles the divide by zero expection
I tried this , please check my answer , is this correct answer ? Help me #code Try: Def divide(a,b) Return ("answer is :",a/b) Y=float(input("enter your number")) X=float(input("enter your number")) Print(divide(x,y)) Except: Print("error : " ,"there is zerodivision error")
2 ответов
+ 6
HO DL
There were lots of mistakes buddy.
May I suggest that you test concepts of your code as you write it, don't just write a complete code, then wonder why it doesn't work.
A variant of your code attached
def divide(a,b):
return a/b
try:
x = float(input())
y = float(input())
print(divide(x,y))
except:
print("error: There is a zero division error")
0
And you can also change to modify to something like this
def divide(a,b):
return "answer is %s"%str(a/b)