+ 15
How does this work or why it does not work :)?
5 Réponses
+ 15
Thanks ! ! !
+ 3
https://code.sololearn.com/cC9tijb0w2VE/#py
# Testing DIV/0 exception catching
try:
num1 = 7
num2 = 0
print (num1 / num2)
print("Done calculation")
except ZeroDivisionError:
print("An error occurred")
print("due to zero division")
# Testing normal functionality
try:
num1 = 7
num2 = 1
print (num1 / num2)
print("Done calculation")
except ZeroDivisionError:
print("An error occurred")
print("due to zero division")
+ 3
I think?? that you are tried to perform nested try, except block....
Just two modification for that...give 'colan' and 'intention' for except...in your code...
And thanks for your question I didn't know this before......
Modification of your code ..
https://code.sololearn.com/cbyQvStRoD3A/?ref=app
+ 2
To explain why your code wasn't working, you got a couple things wrong on it.
- You have a random 'try' right after your 'except' which will generate a compile error.
- You have a random 'except' after your 'zerodivisionerror' except, which also causes a compile error.
:::: CODE WITH ERROR ::::
except ZeroDivisionError:
try
print("An error occurred")
print("due to zero division")
except
^remove the try and remove the last except.