The problem describes a scenario where a customer orders a product with a listed price of $100, but is charged $110 at checkout due to a hidden delivery cost of $10. This cost is not disclosed until the checkout stage. Below is a Python function that calculates the total cost including the hidden delivery fee:
def calculate_total_price(product_price, delivery_cost=10):
"""
Calculate the total price including a fixed hidden delivery cost.
Args:
product_price (float): The listed price of the product.
delivery_cost (float, optional): The hidden delivery cost. Defaults to $10.
Returns:
float: Total price including delivery cost.
"""
return product_price + delivery_cost
product_price = 100.0
total_price = calculate_total_price(product_price)
print(f"Total price: ${total_price:.2f}") # Output: Total price: $110.00
Explanation:
-
Function Definition: The function
calculate_total_pricetakes two parameters:product_price: The base price of the product (e.g., $100).delivery_cost: The hidden delivery fee (defaults to $10 if not specified).
-
Calculation: The total price is computed by adding the product price and the delivery cost:
return product_price + delivery_cost
-
Example: For a product priced at $100, the function returns $110, reflecting the hidden $10 delivery fee.
Key Points:
- Hidden Cost: The delivery cost is not displayed until checkout, encouraging initial purchases without upfront transparency.
- Customization: The
delivery_costparameter allows flexibility to adjust fees (e.g., based on location, weight, or promotions). - Output: The total price is returned as a float, formatted to two decimal places for currency consistency.
This solution models the hidden delivery cost scenario while providing a reusable function for pricing calculations.
Request an On-site Audit / Inquiry