🛠️ToolsShed

흡연 비용 계산기

흡연의 일일·월간·연간 재정 비용과 금연으로 절약할 금액 계산.

자주 묻는 질문

코드 구현

def smoking_cost(packs_per_day, price_per_pack, days=365, annual_return=0.05):
    """
    Calculate the financial cost of smoking and savings from quitting.

    Parameters:
        packs_per_day   - number of packs smoked per day
        price_per_pack  - cost per pack (in your currency)
        days            - number of days to calculate over (default: 365)
        annual_return   - investment return rate if savings are invested (default: 5%)

    Returns a dict with daily, monthly, yearly costs and 10-year invested value.
    """
    daily_cost   = packs_per_day * price_per_pack
    total_cost   = daily_cost * days
    years        = days / 365
    # Future value of regular daily savings invested at annual_return
    r_daily      = annual_return / 365
    if r_daily > 0:
        invested = daily_cost * ((1 + r_daily) ** days - 1) / r_daily
    else:
        invested = total_cost

    return {
        "daily_cost":          daily_cost,
        "monthly_cost":        daily_cost * 30.44,
        "annual_cost":         daily_cost * 365,
        "total_cost":          total_cost,
        "invested_value":      invested,
    }

# Example: 1 pack/day at $10/pack, 10-year projection
result = smoking_cost(1, 10, days=3650, annual_return=0.05)
print(f"Daily cost:        ${result['daily_cost']:.2f}")
print(f"Annual cost:       ${result['annual_cost']:.2f}")
print(f"10-year cost:      ${result['total_cost']:.2f}")
print(f"10-year invested:  ${result['invested_value']:.2f}")

Comments & Feedback

Comments are powered by Giscus. Sign in with GitHub to leave a comment.