Luis Kennedy Saavedra Fuentes
EstudianteNicolas Alpargatero
EstudianteHarold Zurita Simon
EstudianteFidel Parabacuto
EstudianteBrayan Estiben Rodallega Saavedra
EstudianteLuis Gutiérrez Aguirre
EstudianteDiego Cruz
EstudianteJose Bismer Carvajal Alzate
EstudianteVictor Ortiz
EstudianteWaldir Zapata Garcia
EstudianteAlejandro Anaya
EstudianteJosé Miguel Reyes
EstudianteLucas Frazzetta
EstudianteDaniel Salazar Munoz
EstudianteLinda Atenea Mejía Usme
Estudiantejose juan martinez
EstudianteJordan Anderson Huayhua Morales
Estudiantejose juan martinez
EstudianteDiego Gilabert
EstudianteSalomon Chambi
EstudianteBrayan Estiben Rodallega Saavedra
EstudianteGonzalo Gutiérrez Castillo
EstudianteJhon Sebastián Monsalve Gomez
EstudianteLos test ya en los ejercicios anteriores me estaba haciendo dudar cuando hacian el test. Pero en este ejercicio si ya lo demostró
Debería ponerle un poco más de cuidado porque uno pensando que la falla la tiene el código nuestro sigo dandole horas de más en el código y se pierde tiempo en avanzar el reto.
Me quede con las ganas de la serpentina. Pero en el fondo sabemos que está bien 😅
Solución 😄… Se intentó, pero parece que hay bugs en los primeros 2 tests. Sería genial si pudieran revisarlo, saludos 👋. .
from product import Product class Article(Product): def __init__(self, name, price, quantity): super().__init__(name, price, quantity) def addToCart(self): return f"Agregando {self.quantity} unidades del artículo {self.name} al carrito" class Service(Product): def __init__(self, name, price, quantity): super().__init__(name, price, quantity) def addToCart(self): return f"Agregando el servicio {self.name} al carrito" class Cart: def __init__(self): self.products = [] def addProduct(self, product): product.addToCart() self.products.append(product) def deleteProduct(self, product): self.products.remove(product) def calculateTotal(self): return sum( product.price * product.quantity for product in self.products ) def getProducts(self): return self.products
Hay un error me parece: No pasan estas dos pruebas ni colocando la solución que da la plataforma
test_article_instance_of_product assert False is True + where False = isinstance(<main.Article object at 0x1b55820>, Product) test_service_instance_of_product assert False is True + where False = isinstance(<main.Service object at 0x1be8e98>, Product)
Sí, tal parece anda mal...
class Article(Product): def addToCart(self): return f"Agregando {self.quantity} unidades del artículo {self.name} al carrito" class Service(Product): def addToCart(self): return f"Agregando el servicio {self.name} al carrito" class Cart: def __init__(self): self.products = [] def addProduct(self, product): self.products.append(product) return product.addToCart() def deleteProduct(self, product): self.products.remove(product) def calculateTotal(self): return sum(product.price * product.quantity for product in self.products) def getProducts(self): return self.products
Aquí mi solución, a seguir practicando
Hola, mi solucion, ya van varios test que apesar que el codigo cumple muestran error. deberian revisar eso. gracias
from product import Product class Article(Product): def __init__(self, name, price, quantity): super().__init__(name, price, quantity) def addToCart(self): return f"Agregando {self.quantity} unidades del artículo {self.name} al carrito" class Service(Product): def __init__(self, name, price, quantity): super().__init__(name, price, quantity) def addToCart(self): return f"Agregando el servicio {self.name} al carrito" class Cart: def __init__(self): self.productos = [] def addProduct(self, product): print(product.addToCart()) self.productos.append(product) def deleteProduct(self, product): if product in self.productos: self.productos.remove(product) def calculateTotal(self): return sum(p.price for p in self.productos) def getProducts(self): return self.productos ```from product import Product class Article(Product): def \_\_init\_\_(self, name, price, quantity): super().\_\_init\_\_(name, price, quantity) def addToCart(self): return f"Agregando {self.quantity} unidades del artículo {self.name} al carrito" class Service(Product): def \_\_init\_\_(self, name, price, quantity): super().\_\_init\_\_(name, price, quantity) def addToCart(self): return f"Agregando el servicio {self.name} al carrito" class Cart: def \_\_init\_\_(self): self.productos = \[] def addProduct(self, product): print(product.addToCart()) self.productos.append(product) def deleteProduct(self, product): if product in self.productos: self.productos.remove(product) def calculateTotal(self): return sum(p.price for p in self.productos) def getProducts(self): return self.productos
from product import Product class Article(Product): def addToCart(self): print(f"Agregando {self.quantity} unidades del artículo {self.name} al carrito") return f"Agregando {self.quantity} unidades del artículo {self.name} al carrito" class Service(Product): def addToCart(self): print(f"Agregando el servicio {self.name} al carrito") return f"Agregando el servicio {self.name} al carrito" class Cart: def __init__(self): self.products = [] def addProduct(self, product): product.addToCart() self.products.append(product) def deleteProduct(self, product): #self.products.remove(product) self.products = [item for item in self.products if item.name != product.name] def calculateTotal(self): return sum(product.price * product.quantity for product in self.products) def getProducts(self): return self.products def listarProducts(self): for product in self.products: print(product.name, product.price, product.quantity) book = Article("Libro", 100, 2); course = Service("Curso", 120, 1); cart = Cart() cart.addProduct(book) cart.addProduct(course) book = Article("Libro", 100, 2) course = Service("Curso", 120, 1) cart.addProduct(book) cart.addProduct(course) print(cart.calculateTotal()) cart.listarProducts() cart.deleteProduct(book) print(cart.calculateTotal()) cart.listarProducts() ```from product import Product class Article(Product): def addToCart(self): print(f"Agregando {self.quantity} unidades del artículo {self.name} al carrito") return f"Agregando {self.quantity} unidades del artículo {self.name} al carrito" class Service(Product): def addToCart(self): print(f"Agregando el servicio {self.name} al carrito") return f"Agregando el servicio {self.name} al carrito" class Cart: def \_\_init\_\_(self): self.products = \[] def addProduct(self, product): product.addToCart() self.products.append(product) def deleteProduct(self, product): #self.products.remove(product) self.products = \[item for item in self.products if item.name != product.name] def calculateTotal(self): return sum(product.price \* product.quantity for product in self.products) def getProducts(self): return self.products def listarProducts(self): for product in self.products: print(product.name, product.price, product.quantity) book = Article("Libro", 100, 2);course = Service("Curso", 120, 1); cart = Cart()cart.addProduct(book)cart.addProduct(course) book = Article("Libro", 100, 2)course = Service("Curso", 120, 1) cart.addProduct(book)cart.addProduct(course)print(cart.calculateTotal())cart.listarProducts() cart.deleteProduct(book)print(cart.calculateTotal())cart.listarProducts()
Mi solucion:. . . . . . . . . . . . . . . . .
from product import Product class Article(Product): def addToCart(self): # Tu código aquí 👈 return f'Agregando {self.quantity} unidades del artículo {self.name} al carrito' class Service(Product): def addToCart(self): # Tu código aquí 👈 return f'Agregando el servicio {self.name} al carrito' class Cart: def __init__(self): # Tu código aquí 👈 self.shoppingList = [] def addProduct(self, product): # Tu código aquí 👈 product.addToCart() self.shoppingList.append(product) def deleteProduct(self, product): # Tu código aquí 👈 for item in self.shoppingList: if item.name == product.name: self.shoppingList.remove(product) break def calculateTotal(self): # Tu código aquí 👈 return sum(item.price * item.quantity for item in self.shoppingList) def getProducts(self): # Tu código aquí 👈 return self.shoppingList
it's ok
🛡️🛡️Escudo anti-spoilers🛡️🛡️
Mi solución al reto (aunque no se puede completar por el error que tiene la plataforma en los 2 primeros test):
from product import Product class Article(Product): def addToCart(self): #print(f"Agregando {self.quantity} unidades del articulo {self.name}") return f"Agregando {self.quantity} unidades del articulo {self.name}" class Service(Product): def addToCart(self): #print(f"Agregando el servicio {self.name} al carrito") return f"Agregando el servicio {self.name} al carrito" class Cart: def __init__(self): self.products = [] def addProduct(self, product): self.products.append(product) product.addToCart() def deleteProduct(self, product): self.products = [p for p in self.products if p.name != product.name] def calculateTotal(self): #print(sum(p.price * p.quantity for p in self.products)) return sum(p.price * p.quantity for p in self.products) def getProducts(self): return self.products
Mi solución (con los dos mismos errores que les arroja al resto de compañeros en los dos primeros test del Playground)
from product import Product class Article(Product): def addToCart(self): return f"Agregando {self.quantity} unidades del artículo {self.name} al carrito" class Service(Product): def addToCart(self): return f"Agregando el servicio {self.name} al carrito" class Cart: def __init__(self): self.products = [] def addProduct(self, product): self.products.append(product) print(product.addToCart()) def deleteProduct(self, product): self.products.remove(product) def calculateTotal(self): total = sum(product.price * product.quantity for product in self.products) return total def getProducts(self): return self.products
Pensé que me iba a resultar más complicado pero pasé bien! Excepto los dos primeros test como todo el mundo jajaja . . . . .. . . . .
from product import Product class Article(Product): def addToCart(self): return f"Agregando {self.quantity} unidades del artículo {self.name} al carrito" pass class Service(Product): def addToCart(self): return f"Agregando el servicio {self.name} al carrito" pass class Cart: def __init__(self): self.products = [] pass def addProduct(self, product): product.addToCart() self.products.append(product) pass def deleteProduct(self, product): self.products = [prod for prod in self.products if prod.name != product.name ] pass def calculateTotal(self): total = 0 for product in self.products: total += product.quantity * product.price return total pass def getProducts(self): return self.products pass
No entendí por qué el test validan que la subclase no sea instancia de la superclase si tengo entendido que por heredar de ella esto la hace una instancia, aun así comparto el logro:
from product import Product class Article(Product): def __init__(self, name, price, quantity): super().__init__(name, price, quantity) def addToCart(self): return f"Agregando {self.quantity} unidades del artículo {self.name} al carrito" class Service(Product): def __init__(self, name, price, quantity): super().__init__(name, price, quantity) def addToCart(self): return f"Agregando el servicio {self.name} al carrito" class Cart: def __init__(self): self.basket = [] def addProduct(self, product): product.addToCart() self.basket.append(product) def deleteProduct(self, product): self.basket.remove(product) def calculateTotal(self): return sum(item.price * item.quantity for item in self.basket) def getProducts(self): return self.basket
from product import Product class Article(Product): def addToCart(self): return f"Agregando {self.quantity} unidades del artículo {self.name} al carrito" class Service(Product): def addToCart(self): return f"Agregando el servicio {self.name} al carrito" class Cart: def __init__(self): self.cart_list = [] def addProduct(self, product): self.cart_list.append(product) product.addToCart() def deleteProduct(self, product): self.cart_list.remove(product) def calculateTotal(self): return sum(product_in_cart.price * product_in_cart.quantity for product_in_cart in self.cart_list) def getProducts(self): return self.cart_list
no se olviden que también para designar variables desde la clase padre se debe poner:
class Article(Product): def __init__(self,name,price,quantity): super().__init__(name,price,quantity) class Service(Product): def __init__(self,name,price,quantity): super().__init__(name,price,quantity)
¿Exactamente en dónde va eso?
este va justo en el constructor de las clases hijas (donde se asignan los atributos de la clase)
. . . . . . . . . . . . . . .Mi codigo, no encontre como resolver los primeros dos test :(
from product import Product class Article(Product): def __init__(self, name, price, quantity): super().__init__(name, price, quantity) def addToCart(self): return f"Agregando {self.quantity} unidades del artículo {self.name} al carrito" class Service(Product): def __init__(self, name, price, quantity): super().__init__(name, price, quantity) def addToCart(self): return f"Agregando el servicio {self.name} al carrito" class Cart: def __init__(self): self.products = [] def addProduct(self, product): self.products.append(product) print(product.addToCart()) def deleteProduct(self, product): self.products.remove(product) def calculateTotal(self): return sum(i.price * i.quantity for i in self.products) def getProducts(self): return self.products
from product import Product class Article(Product): def addToCart(self): return f'Agregando {self.quantity} unidades del artículo {self.name} al carrito' class Service(Product): def addToCart(self): return f'Agregando el servicio {self.name} al carrito' class Cart: def __init__(self): self.arr = [] self.total = 0 def addProduct(self, product): self.arr.append(product) product.addToCart() def deleteProduct(self, product): self.arr.remove(product) def calculateTotal(self): for p in self.arr: self.total += (p.price * p.quantity) return self.total def getProducts(self): return self.arr
from product import Product class Article(Product): def addToCart(self): return f"Agregando {self.quantity} unidades del artículo {self.name} al carrito" class Service(Product): def addToCart(self): return f"Agregando el servicio {self.name} al carrito" class Cart: def __init__(self): self.cart_list = [] def addProduct(self, product): if product != None: self.cart_list.append(product) return product.addToCart() def deleteProduct(self, product): if product in self.cart_list: self.cart_list.remove(product) def calculateTotal(self): total = 0 for item in self.cart_list: total += item.price * item.quantity return total def getProducts(self): return self.cart_list
from product import Product class Article(Product): def __init__(self, name, price, quantity): super().__init__(name,price,quantity) def addToCart(self): return f"Agregando {self.quantity} unidades del artículo {self.name} al carrito" class Service(Product): def __init__(self, name, price, quantity): super().__init__(name,price,quantity) def addToCart(self): return f"Agregando el servicio {self.name} al carrito" class Cart: def __init__(self): self.cartList = [] def addProduct(self, product): self.cartList.append(product) print(product.addToCart()) def deleteProduct(self, product): self.cartList.remove(product) def calculateTotal(self): total = 0 for product in self.cartList: total+=(product.price*product.quantity) return total def getProducts(self): return self.cartList book = Article("Libro", 100, 2); course = Service("Curso", 120, 1); cart = Cart(); cart.addProduct(book); cart.addProduct(course); print(cart.getProducts()) print(cart.calculateTotal())```
Aqui mi solucion: . . . . . . . . .
from product import Product class Article(Product): def addToCart(self): # Tu código aquí 👈 return f'Agregando {self.quantity} unidades del artículo {self.name} al carrito' class Service(Product): def addToCart(self): # Tu código aquí 👈 return f'Agregando el servicio {self.name} al carrito' class Cart: def __init__(self): # Tu código aquí 👈 self.total_product = 0 self.shopping_cart = [] def addProduct(self, product): # Tu código aquí 👈 product.addToCart() self.shopping_cart.append(product) def deleteProduct(self, product): # Tu código aquí 👈 self.shopping_cart.remove(product) def calculateTotal(self): # Tu código aquí 👈 for item in self.shopping_cart: self.total_product += item.price * item.quantity return self.total_product def getProducts(self): # Tu código aquí 👈 return self.shopping_cart