I was wondering if we can execute our code entirely in the try section without using else.
Obviously it works. here is an example:
x = int(input())
try:
print(10/x)
print("Possible")
except ZeroDivisionError as e:
print(e)
Or we can do this which is the mostly used syntax:
x = int(input())
try:
print(10/x)
except ZeroDivisionError as e:
print(e)
else:
print("Possible")
We can even use a condition in this case:
x = int(input())
if x !=0:
print(10/x)
print("possible")
elif x ==0 :
print("Error!")
So what is the difference between these three? which one should be used? all three seem to be able to catch and prevent errors.