Skip to content
Merged
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
16 changes: 16 additions & 0 deletions python/Modulo-08-POO/71-clases-objetos/reto.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
class Monstruo:
def __init__(self, nombre, asustador):
self.nombre = nombre
self.asustador = asustador

def rugir(self):
if self.asustador:
print(f"¡ROAAAR! Soy {self.nombre} y doy mucho miedo.")
else:
print(f"Grrr... Soy {self.nombre} pero soy amigable.")

sulley = Monstruo("Sulley", True)
mike = Monstruo("Mike", False)

sulley.rugir()
mike.rugir()
12 changes: 12 additions & 0 deletions python/Modulo-08-POO/72-init/reto.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
class CuentaBancaria:
def __init__(self, titular):
self.titular = titular
self.saldo = 0

def depositar(self, cantidad):
self.saldo += cantidad
print(f"Depositaste {cantidad}. Saldo actual: {self.saldo}")

cuenta_batman = CuentaBancaria("Batman")
cuenta_batman.depositar(500)
cuenta_batman.depositar(1000)
20 changes: 20 additions & 0 deletions python/Modulo-08-POO/73-herencia-polimorfismo/reto.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
class Vehiculo:
def __init__(self, marca):
self.marca = marca

def arrancar(self):
print(f"El vehículo {self.marca} está encendido.")

class Coche(Vehiculo):
def arrancar(self):
print(f"¡Brum brum! El coche {self.marca} ha arrancado.")

class Bicicleta(Vehiculo):
def arrancar(self):
print(f"¡Ring ring! La bicicleta {self.marca} está en marcha.")

mi_coche = Coche("Toyota")
mi_bici = Bicicleta("Trek")

mi_coche.arrancar()
mi_bici.arrancar()
14 changes: 14 additions & 0 deletions python/Modulo-08-POO/74-encapsulamiento/reto.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
class CajaFuerte:
def __init__(self, contraseña):
self.__contraseña = contraseña
self.__dinero = 1000

def abrir_caja(self, intento):
if intento == self.__contraseña:
print(f"🔓 Caja abierta. Tienes {self.__dinero} dólares.")
else:
print("🚨 ¡Alarma! Intruso detectado.")

mi_caja = CajaFuerte("secreto123")
mi_caja.abrir_caja("0000")
mi_caja.abrir_caja("secreto123")
19 changes: 19 additions & 0 deletions python/Modulo-08-POO/75-propiedades/reto.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
class Cine:
def __init__(self):
self.__edad_cliente = 0

@property
def edad(self):
return self.__edad_cliente

@edad.setter
def edad(self, nueva_edad):
if nueva_edad < 18:
print("Acceso denegado. Eres menor de edad.")
else:
self.__edad_cliente = nueva_edad
print("Acceso concedido. Disfruta la película.")

mi_cine = Cine()
mi_cine.edad = 15
mi_cine.edad = 20
16 changes: 16 additions & 0 deletions python/Modulo-08-POO/76-metodos-clase/reto.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
class Pizzeria:
pizzas_vendidas = 0

def __init__(self, sabor):
self.sabor = sabor
Pizzeria.pizzas_vendidas += 1

@classmethod
def reporte_ventas(cls):
print(f"¡Hemos vendido {cls.pizzas_vendidas} pizzas en total!")

pizza1 = Pizzeria("Pepperoni")
pizza2 = Pizzeria("Hawaiana")
pizza3 = Pizzeria("Queso")

Pizzeria.reporte_ventas()
10 changes: 10 additions & 0 deletions python/Modulo-08-POO/77-dunder-methods/reto.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
class Platillo:
def __init__(self, nombre, precio):
self.nombre = nombre
self.precio = precio

def __str__(self):
return f"{self.nombre} - ${self.precio}"

mi_cena = Platillo("Pizza Familiar", 15)
print(mi_cena)
20 changes: 20 additions & 0 deletions python/Modulo-08-POO/78-abstraccion/reto.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
from abc import ABC, abstractmethod

class MetodoPago(ABC):
@abstractmethod
def procesar_pago(self, cantidad):
pass

class TarjetaCredito(MetodoPago):
def procesar_pago(self, cantidad):
print(f"💳 Cobrando ${cantidad} de la tarjeta de crédito.")

class Paypal(MetodoPago):
def procesar_pago(self, cantidad):
print(f"📧 Transfiriendo ${cantidad} desde la cuenta de Paypal.")

tarjeta = TarjetaCredito()
paypal = Paypal()

tarjeta.procesar_pago(150)
paypal.procesar_pago(50)
22 changes: 22 additions & 0 deletions python/Modulo-08-POO/79-singleton/reto.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
class BovedaCentral:
_unica_boveda = None

def __new__(cls):
if cls._unica_boveda is None:
cls._unica_boveda = super().__new__(cls)
return cls._unica_boveda

def __init__(self):
if not hasattr(self, 'dinero_total'):
self.dinero_total = 0

def depositar(self, cantidad):
self.dinero_total += cantidad

sucursal_norte = BovedaCentral()
sucursal_sur = BovedaCentral()

sucursal_norte.depositar(500)
sucursal_sur.depositar(300)

print("Dinero en la sucursal sur:", sucursal_sur.dinero_total)
56 changes: 56 additions & 0 deletions python/Modulo-08-POO/80-RETO-ecosistema/reto.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
from abc import ABC, abstractmethod

class CentroControl:
_instancia = None

def __new__(cls):
if cls._instancia is None:
cls._instancia = super().__new__(cls)
return cls._instancia

def iniciar_lanzamiento(self):
print("🎙️ Centro de Control: Iniciando secuencia de despegue...")

class Nave(ABC):
_naves_creadas = 0

def __init__(self, nombre, combustible):
self.nombre = nombre
self.__combustible = combustible
Nave._naves_creadas += 1

@classmethod
def total_naves(cls):
return cls._naves_creadas

@property
def combustible(self):
return self.__combustible

@abstractmethod
def despegar(self):
pass

def __str__(self):
return f"🛸 Nave {self.nombre} - Combustible: {self.combustible}%"

class Explorador(Nave):
def despegar(self):
print(f"🛰️ {self.nombre} encendiendo motores ligeros. ¡Hacia las estrellas!")

class Carguero(Nave):
def despegar(self):
print(f"🚀 {self.nombre} encendiendo propulsores pesados. ¡Levantando carga!")

centro = CentroControl()
centro.iniciar_lanzamiento()

voyager = Explorador("Voyager", 100)
titan = Carguero("Titan", 80)

print(f"Total de naves listas: {Nave.total_naves()}")
print(voyager)
print(titan)

voyager.despegar()
titan.despegar()
Loading