JustCaptain kod-buduschego
7efceb421dbc5c7b77700ed9dbec228ce6d15358
Перейти к файлу
Код
main.py
""" """


def calculate_customer_discount(customer_type: str) -> int:
    if customer_type == "vip":
        return 5
    elif customer_type == "regular":
        return 0
    else:
        raise ValueError


def calculate_order_discount(order_amount: int | float) -> int:
    if order_amount < 50:
        return 0
    elif 50 <= order_amount <= 100:
        return 5
    elif 100 <= order_amount <= 200:
        return 10
    else:
        return 15


def calculate_fragile_fee(fragile: bool) -> int:
    if fragile:
        return 6
    return 0


def calculate_priority_fee(priority: str) -> int:
    if priority == "express":
        return 10
    elif priority == "standard":
        return 0
    else:
        raise ValueError


def calculate_distance_cost(distance: int | float) -> int:
    if distance <= 0:
        raise ValueError

    if distance < 3:
        return 3
    elif 50 <= distance <= 200:
        return 7
    elif 200 <= distance <= 500:
        return 15
    else:
        return 25


def calculate_weight_cost(weight: int | float) -> int | float:
    if weight <= 0:
        raise ValueError

    if weight < 1:
        return 5
    elif 1 <= weight <= 5:
        return 8
    elif 5 <= weight <= 10:
        return 12
    else:
        return 12 + ((weight - 10) * 12)


def calculate_total_delivery_cost(
    weight: int | float,
    distance: int,
    order_amount: int | float,
    priority: str = "standard",
    fragile: bool = False,
    customer_type: str = "regular",
    debug: bool = False,
):
    price_weight: int | float = calculate_weight_cost(weight=weight)
    price_distance: int = calculate_distance_cost(distance=distance)
    price_prority: int = calculate_priority_fee(priority=priority)
    price_fragile: int = calculate_fragile_fee(fragile=fragile)
    total_price: float = price_weight + price_distance + price_prority + price_fragile

    customer_discount: int = calculate_customer_discount(customer_type=customer_type)
    order_discount: int = calculate_order_discount(order_amount=order_amount)
    total_discount = customer_discount + order_discount
    result: int | float = total_price - (total_price / 100 * total_discount)
    if debug:
        report: str = (
            f"Weight cost: {price_weight}\nDistance cost: {price_distance}\nPriority fee: {price_prority}\nFragilefee: {price_fragile}\nTotal before discount: {total_price}\nDiscount: {total_discount}\nFinal cost: {result}"
        )
        print(report)
    return result


cost: int | float = calculate_total_delivery_cost(
    weight=7,
    distance=120,
    order_amount=180,
    priority="express",
    fragile=True,
    customer_type="vip",
    debug=True,
)
print(cost)