Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions exercises/exercise1.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,15 @@ class Circle:
- Utilizar Type Hints en todos los métodos y variables
"""

def __init__(self, radio): # Variable de instancia
self.radio = radio

def area(self): # Metodo de instancia
return round((pi * (self.radio ** 2)), 2)

def perimetro(self):
return round((2 * pi * self.radio), 2)


# NO MODIFICAR - INICIO
# Test básico
Expand Down
19 changes: 18 additions & 1 deletion exercises/exercise2.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class Article:
los descuentos si hubiera. Redondear a 2 decimales.

Restricciones:
- Utilizar 3 variables de instancia
- Utilizar 3 variables de instancia *
- Utilizar 1 método de instancia
- Utilizar 1 variable de clase
- Utilizar 1 método de clase
Expand All @@ -21,6 +21,23 @@ class Article:
- Utilizar Type Hints en todos los métodos y variables
"""

__iva = 0.21 # Variable de clase (fuera del metodo constructor)

def __init__(self, nombre: str, costo: float, descuento: float = None) -> None:
self.nombre = nombre
self.costo = costo
self.descuento = descuento

def calcular_precio(self) -> float:
precio = (self.costo + (self.costo * self.__iva))
if self.descuento != None:
return round(precio - (precio * self.descuento), 2)
return round(precio, 2)

@classmethod # Metodo de clase
def actualizar_iva(cls, iva: float) -> None:
cls.__iva = iva # cls hace referencia a la clase


# NO MODIFICAR - INICIO
# Test parámetro obligatorio
Expand Down
18 changes: 18 additions & 0 deletions exercises/exercise3.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,24 @@ class Article:
- Utilizar Type Hints en todos los métodos y variables
"""

__iva = 0.21

def __init__(self, nombre: str, costo: float, descuento: float = None) -> None:
self.nombre = nombre
self.costo = costo
self.descuento = descuento

@property
def precio(self) -> float:
precio = (self.costo + (self.costo * self.__iva))
if self.descuento != None:
return round(precio - (precio * self.descuento), 2)
return round(precio, 2)

@classmethod
def actualizar_iva(cls, iva: float) -> None:
cls.__iva = iva


# NO MODIFICAR - INICIO
# Test parámetro obligatorio
Expand Down
13 changes: 13 additions & 0 deletions exercises/exercise4.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,19 @@
"""


@dataclass
class Materia:
nombre: str


@dataclass
class Carrera:
materias: list

def __len__(self) -> int:
return len(self.materias)


# NO MODIFICAR - INICIO
# Test parámetro obligatorio
try:
Expand Down
45 changes: 43 additions & 2 deletions exercises/exercise5.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,56 @@
from typing import List


"""Data una lista de contribuyentes, devuelve una lista de los sueldos de
cada uno."""


@dataclass
class Contribuyente(ABC):

@abstractmethod
def calcular_sueldo() -> float:
pass


@dataclass
class Empleado(Contribuyente):
monto: float

def calcular_sueldo(self) -> float:
return self.monto - (self.monto * 0.17)


@dataclass
class Monotributista(Contribuyente):
monto: float

def calcular_sueldo(self) -> float:
if (self.monto < (370000/12)):
return self.monto - 2646.22
elif (self.monto < (5500000/12)):
return self.monto - 2958.95
elif (self.monto < (770000/12)):
return self.monto - 3382.62
elif (self.monto > (770000/12)):
return self.monto - 3988.85


def calcular_sueldos(contribuyentes: List[Contribuyente]):
"""Data una lista de contribuyentes, devuelve una lista de los sueldos de
cada uno."""

sueldos = []

for i in contribuyentes:
sueldos.append(i.calcular_sueldo())
return sueldos


# NO MODIFICAR - INICIO
assert type(Contribuyente) == abc.ABCMeta, "Contribuyente debe ser abstracta"
assert issubclass(Empleado, Contribuyente), "Empleado debe heredar de Contribuyente" # noqa: 501
assert issubclass(Monotributista, Contribuyente), "Monotributista debe heredar de Contribuyente" # noqa: 501
assert issubclass(Empleado, Contribuyente), "Empleado debe heredar de Contribuyente" # noqa: 501
assert issubclass(Monotributista, Contribuyente), "Monotributista debe heredar de Contribuyente" # noqa: 501

try:
juan = Contribuyente()
Expand Down