second number first numberq the tryexceptelse block works like thispython attempts to run the code in the try statement the only code that should go in try statement is code that might cause an exception to be raised sometimes you'll have additional code that should run only if the try block was successfulthis code goes in the else block the except block tells python what to do in case certain exception arises when it tries to run the code in the try statement by anticipating likely sources of errorsyou can write robust programs that continue to run even when they encounter invalid data and missing resources your code will be resistant to innocent user mistakes and malicious attacks handling the filenotfounderror exception one common issue when working with files is handling missing files the file you're looking for might be in different locationthe filename may be misspelledor the file may not exist at all you can handle all of these situations in straightforward way with tryexcept block let' try to read file that doesn' exist the following program tries to read in the contents of alice in wonderlandbut haven' saved the file alice txt in the same directory as alice pyalice py filename 'alice txtwith open(filenameas f_objcontents f_obj read(python can' read from missing fileso it raises an exceptiontraceback (most recent call last)file "alice py"line in with open(filenameas f_objfilenotfounderror[errno no such file or directory'alice txtthe last line of the traceback reports filenotfounderrorthis is the exception python creates when it can' find the file it' trying to open in this examplethe open(function produces the errorso to handle itthe try block will begin just before the line that contains open()filename 'alice txttrywith open(filenameas f_objcontents f_obj read(files and exceptions