you can use finallyblock along with tryblock the finally block is place to put any code that must executewhether the try-block raised an exception or not syntax try#run this action first exceptrun if exception occurs finally #always run this code exampletrynum int(input("enter the number ")re /num exceptprint ("something is wrong"elseprint ("result is ",refinallyprint ("finally program ends"outputenter the number result is finally program ends enter the number something is wrong finally program ends enter the number something is wrong finally program ends the finally-block is executed once the try-block is complete and any raised exceptions have been handled infect finally block will run even if new exception is raised raising an exception in python programmingexceptions are raised when corresponding errors occur at run timebut we can force specified exception to occur using the keyword raise to trigger exceptions explicitlyyou can code raise statements page