+ 1
Hello friend i have doubt in this program ?
I am using try except else finally block .if i give input 4,0 the program is crash even though i use except block because the else block is excuted here How else block will execute here because else block excuted when there is no problem in try block but there is problem i give zero as input but also the else part is excuted how? Can anyone explain me i https://code.sololearn.com/c7Off7ut0RZe/?ref=app
3 Respostas
+ 4
Your try block only includes the input of the numbers. If the input doesn't fail (and why would it?), there won't be any exception. The crucial part is a/b (where the ZeroDivision error would happen), but this one is not in a try statement. Change it to:
# input...
try:
print(a/b)
except ZeroDivisionError:
# error message
finally:
# whatever
+ 2
Thank you so much Anna😄
+ 2
You're welcome 😊