the statements that can raise the exception are placed inside the try blockand the code that handles is placed inside except block here try and except are keywords the syntax for tryexcept can be as given bellowtrystatements except exceptionnamestatements the try statement works as follows firstthe try block (the statement(sbetween the try and except keywordsis executed if no exception occursthe except block is skipped and execution of the try statement is finished if an exception occurs during execution of the try blockthe rest of the block is skipped then if its type matches the exception named after the except keywordthe except block is executedand then execution continues after the try statement if an exception occurs which does not match the exception named in the except blockit is passed on to outer try statementsif no handler is foundit is an unhandled exception and execution stops with message example program exception py #program without exception handler =int(input("enter value") =int(input("enter value")print("the sum is:", +yprint("the suntraction is:", -yprint("the quotient is:", /yprint("the product is:", *yprint("the remainder is:", %yprint("the power of ^ si:", **youtput enter value enter value the sum is the suntraction is traceback (most recent call last)file " :/python/exception py"line in print("the quotient is:", /yzerodivisionerrordivision by zero exception py =int(input("enter value") =int(input("enter value")print("the sum is:", +yprint("the suntraction is:", -ytryprint("the quotient is:", /yprint("the remainder is:", %yexcept zerodivisionerrorprint("you should not divide number with zero"#legal code print("the product is:", *yprint("the power of ^ si:", **youtput enter value enter value the sum is the suntraction is you should not divide number with zero the product is the power of ^ si multiple except blocks python allows you to have multiple except blocks for single try block the block that matches with exception will be executed try block can be associated with one or more except block howeveronly one block will be executed at time page