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 | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 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

2nd Aug 2016, 12:02 AM
nikitha gireddy
nikitha gireddy - avatar
3 Answers
+ 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
2nd Aug 2016, 5:01 PM
Sruti Sarayan
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 .
3rd Aug 2016, 7:45 PM
Chintu Kumar
Chintu Kumar - avatar
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")
4th Aug 2016, 7:17 PM
Bharath kishore
Bharath kishore - avatar