tummy.com, ltd.

#!/usr/bin/env python2
#
#  Demonstrate exceptions

def divmod(lhs, rhs):
   return(lhs / rhs, lhs % rhs)

def showdivmod(lhs, rhs):
   result = divmod(lhs, rhs)
   print '%s/%s=%s\t%s%%%s=%s' % ( lhs, rhs, result[0], lhs, rhs, result[1] )

try:
   showdivmod(5, 6)
   showdivmod(10, 6)
   showdivmod(15, 0)
except ZeroDivisionError:
   print 'Whoa!  Caught zero division!'

Contact

Privacy Policy
Copyright © 1995-2003 tummy.com, ltd, All Rights Reserved
5400 Fossil Court North, Fort Collins, Colorado, USA, 80525
Last modified on 2004-06-07
Python programming makes us more efficient.