if you know that line of code might raise an exception when executedyou should handle the exception in well-written programunhandled exceptions should be the exception consider the code successfailureratio numsuccesses/float(numfailuresprint 'the success/failure ratio is'successfailureratio print 'now heremost of the timethis code will work just finebut it will fail if numfailures happens to be zero the attempt to divide by zero will cause the python runtime system to raise zerodivisionerror exceptionand the print statements will never be reached it would have been better to have written something along the lines of trysuccessfailureratio numsuccesses/float(numfailuresprint 'the success/failure ratio is'successfailureratio except zerodivisionerrorprint 'no failures so the success/failure ratio is undefined print 'now hereupon entering the try blockthe interpreter attempts to evaluate the expression numsuccesses/float(numfailuresif expression evaluation is successfulthe program assigns the value of the expression to the variable successfailureratioexecutes the print statement at the end of the try blockand proceeds to the print statement following the try-except ifhowevera zerodivisionerror exception is raised during the expression evaluationcontrol immediately jumps to the except block (skipping the assignment and the print statement in the try block)the print statement in the except block is executedand then execution continues at the print statement following the try-except block finger exerciseimplement function that meets the specification below use try-except block def sumdigits( )"""assumes is string returns the sum of the decimal digits in for exampleif is ' cit returns ""let' look at another example consider the code val int(raw_input('enter an integer')print 'the square of the number you entered is'val** if the user obligingly types string that can be converted to an integereverything will be fine but suppose the user types abcexecuting the line of code will cause the python runtime system to raise valueerror exceptionand the print statement will never be reached