Advertisement
Fhernd

delegar_acceso_atributo.py

Jan 7th, 2019
1,022
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.48 KB | None | 0 0
  1. class Calculadora:
  2.     def sumar(self, a, b):
  3.         return a + b
  4.  
  5.     def restar(self, a, b):
  6.         return a - b
  7.  
  8.  
  9. class CalculadoraCientifica:
  10.     def __init__(self):
  11.         self._calculadora = Calculadora()
  12.  
  13.     def potencia(self, a, b):
  14.         return a ** b
  15.  
  16.     def __getattr__(self, atributo):
  17.         return getattr(self._calculadora, atributo)
  18.  
  19.  
  20. calc = CalculadoraCientifica()
  21.  
  22. print(calc.potencia(5, 2))
  23. print(calc.sumar(3, 2))
  24. print(calc.restar(3, 2))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement