fork(1) download
  1. class NotBolsheError(Exception):
  2. def __init__(self):
  3. pass
  4.  
  5.  
  6. class BolsheMensher(object):
  7. def __init__(self, a, b):
  8. self.a = a
  9. self.b = b
  10.  
  11. def __str__(self):
  12. try:
  13. self.menshe(is_a=True)
  14. except NotBolsheError:
  15. try:
  16. self.menshe(is_a=False)
  17. except NotBolsheError:
  18. return 'A ravno B'
  19. else:
  20. return 'A bolshe B'
  21. else:
  22. return 'A menshe B'
  23.  
  24. def _set_operands(self, is_a):
  25. return (self.a, self.b) if is_a else (self.b, self.a)
  26.  
  27. def bolshe(self, is_a):
  28. a, b = self._set_operands(is_a)
  29. if a > b:
  30. return True
  31. raise NotBolsheError
  32.  
  33. def ravno(self, is_a):
  34. a, b = self._set_operands(is_a)
  35. if a == b:
  36. return True
  37. self.bolshe(is_a)
  38.  
  39. def menshe(self, is_a):
  40. '''Wrapper over bolshe and ravno methods for user convenience.'''
  41. is_ravno = False
  42. try:
  43. is_ravno = self.ravno(is_a)
  44. except NotBolsheError:
  45. # Safe to return true there.
  46. return True
  47.  
  48. if is_ravno:
  49. # Return NotBolsheError since it is also a case.
  50. raise NotBolsheError
  51. return True
  52.  
  53.  
  54. print(BolsheMensher(6, 4))
  55.  
Success #stdin #stdout 0.01s 47720KB
stdin
Standard input is empty
stdout
A menshe B