Simple exception handling example : Exception Handle : Exception PYTHON examples


PYTHON examples » Exception » Exception Handle »

 

Simple exception handling example


Simple exception handling example
 

number1 = raw_input"Enter numerator: " )
number2 = raw_input"Enter denominator: " )

try:
   number1 = floatnumber1 )
   number2 = floatnumber2 )
   result = number1 / number2
float raises a ValueError exception   
except ValueError:
   print "You must enter two numbers"
except ZeroDivisionError:
   print "Attempted to divide by zero"
else:
   print "%.3f / %.3f = %.3f" number1, number2, result )

           
         
  



Leave a Comment / Note


 
Verification is used to prevent unwanted posts (spam). .


PYTHON examples

 Navioo Exception
» Exception Handle