fork download
  1. class Rect():
  2. def __init__(self, w, h):
  3. self.w = w
  4. self.h = h
  5.  
  6. def calcArea(self):
  7. return self.w * self.h
  8.  
  9. class Circle():
  10. def __init__(self, r):
  11. self.r = r
  12.  
  13. def calcArea(self):
  14. return self.r * self.r * 3.14
  15.  
  16.  
  17. class AreaCalc:
  18. def __init__(self, shapes):
  19. self.shapes = shapes
  20.  
  21. def sumArea(self):
  22. return sum([area.calcArea() for area in self.shapes])
  23.  
  24. class AreaOutput:
  25. def __init__(self, sum):
  26. self.sum = sum
  27.  
  28. def outputSum(self):
  29. print(self.sum)
  30.  
  31. def outputSumRound(self):
  32. print(round(self.sum))
  33.  
  34. circle = Circle(2)
  35. rect = Rect(4, 2)
  36. areaCalc = AreaCalc([circle, rect])
  37. sum = areaCalc.sumArea()
  38. AreaOutput(sum).outputSum()
  39. AreaOutput(sum).outputSumRound()
Success #stdin #stdout 0.02s 27712KB
stdin
Standard input is empty
stdout
20.560000000000002
21