t484.py 671 B

12345678910111213141516171819202122232425262728293031323334
  1. class calculator:
  2. def __init__(self): pass
  3. def div(self, x, y):
  4. try:
  5. return x / y
  6. except ZeroDivisionError:
  7. return "ZeroDivisionError: can't divide by zero"
  8. except NameError as e:
  9. return e
  10. except TypeError as e:
  11. return e
  12. except TypeError:
  13. print "DID NOT CATCH 'TypeError as e'"
  14. return "TypeError"
  15. except:
  16. return "OTHER ERROR"
  17. c = calculator();
  18. print c.div(10,1)
  19. print c.div(10,0)
  20. print c.div('12','6')
  21. try:
  22. print c.div('10','1') / 2
  23. except:
  24. print "ERROR"
  25. try:
  26. print c.div(x,12)
  27. except NameError as e:
  28. print e