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