Exception
Exception
Money transfer,
ex: a/b
where b=0
will get exception,and all code
after the line will get stopped, mns they are not running.
for that we need to handle the exception to resume the flow of program
#exception handling
Try: we have to put the risky code inside the try block.
if there is any chances of expection then the except block will be executed
else the try block itself execute the code.
res=a/b
print("final result",res)
print()
except:
print("cannot devide to zero")
print("hello")
----------------------------------Else block----
if everything inside the try block is correct then always the else block will be
executed.
except:
print("cannot devide to zero")
else:
print("hello")
------------------Assert:
Python provides the assert statement to check if a given logical
exp is true or false.
prog execution proceeds only if the expression is true and raise
the AssertionError when it is false.
eg:
num=15
assert num>=15
try:
num=int(input("entr a no"))
assert num%2==0
print("Number is even")
except AssertionError:
print("pls enter even no")