+ 2
I tried following code try: num1 = 7 num2 = 0 print("Done calculation") print (num1 / num2) except ZeroDivisionError: print("An error occurred") print("due to zero division") It's throwing an error I don't understand why can someone explain me plz
3 odpowiedzi
+ 2
I don't see any problem with the code. The output should be as below because there will be an exception raised when we divide num1(7) by num2(0):
Done Calculation
An error occurred
due to zero division
0
is there anything to do with the gap between num1 and / symbol .
or is it that after printing done calculation it stopped due to zero error in next line .
0
what is the error?
if it says indentationError you need to indent it properly. with not more than one white space.
try:
num1 = 7
num2 = 0
print("Done calculation")
print (num1 / num2)
except(ZeroDivisionError):
print("An error occurred")
print("due to zero division")