Solución
solution.tsTypeScript
ELECTRONICS_DISCOUNT = 0.15
CLOTHING_DISCOUNT = 0.20
FOOD_DISCOUNT = 0.05
DEFAULT_DISCOUNT = 0.0
TAX_RATE = 0.21
def get_discount_rate(category: str ) -> float:
if category == "electronics":
return ELECTRONICS_DISCOUNT
elif category == "clothing":
return CLOTHING_DISCOUNT
elif category == "food":
return FOOD_DISCOUNT
else:
return DEFAULT_DISCOUNT
def get_product_final_price(price: float, category: str, stock: int) -> float:
if stock <= 0 or price <= 0:
return -1
discount_rate = get_discount_rate(category)
price_after_discount = price * (1 - discount_rate)
final_price = price_after_discount * (1 + TAX_RATE)
return round(final_price, 2)
exports = get_product_final_price0respuestas