{"record":{"id":"6a8ae61175823920","repo":"TheAlgorithms/Python","slug":"days-between-payments-must-be-0","errorCode":null,"errorMessage":"days_between_payments must be > 0","messagePattern":"days_between_payments must be > 0","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"financial/interest.py","lineNumber":34,"sourceCode":"    >>> simple_interest(18000.0, 0.0, 3)\n    0.0\n    >>> simple_interest(5500.0, 0.01, 100)\n    5500.0\n    >>> simple_interest(10000.0, -0.06, 3)\n    Traceback (most recent call last):\n        ...\n    ValueError: daily_interest_rate must be >= 0\n    >>> simple_interest(-10000.0, 0.06, 3)\n    Traceback (most recent call last):\n        ...\n    ValueError: principal must be > 0\n    >>> simple_interest(5500.0, 0.01, -5)\n    Traceback (most recent call last):\n        ...\n    ValueError: days_between_payments must be > 0\n    \"\"\"\n    if days_between_payments <= 0:\n        raise ValueError(\"days_between_payments must be > 0\")\n    if daily_interest_rate < 0:\n        raise ValueError(\"daily_interest_rate must be >= 0\")\n    if principal <= 0:\n        raise ValueError(\"principal must be > 0\")\n    return principal * daily_interest_rate * days_between_payments\n\n\ndef compound_interest(\n    principal: float,\n    nominal_annual_interest_rate_percentage: float,\n    number_of_compounding_periods: float,\n) -> float:\n    \"\"\"\n    >>> compound_interest(10000.0, 0.05, 3)\n    1576.2500000000014\n    >>> compound_interest(10000.0, 0.05, 1)\n    500.00000000000045\n    >>> compound_interest(0.5, 0.05, 3)","sourceCodeStart":16,"sourceCodeEnd":52,"githubUrl":"https://github.com/TheAlgorithms/Python/blob/f5988cc09713315817df6a7e327e258013a94440/financial/interest.py#L16-L52","documentation":"Raised by simple_interest() in financial/interest.py when days_between_payments <= 0. Interest here is principal * daily_rate * days, and a non-positive day count is meaningless; this is the first of three ordered checks (days, then rate, then principal), so it fires even if the other arguments are also invalid.","triggerScenarios":"simple_interest(5500.0, 0.01, -5) or days=0; computing days as (end_date - start_date).days when the dates are reversed or equal; a date parse failure yielding a 0-day interval.","commonSituations":"Date-order bugs where payment date precedes the loan date; timezone/DST arithmetic collapsing to 0 days; pipelines where an empty schedule row produces 0 days.","solutions":["Pass a strictly positive integer day count between payments.","When deriving from dates, assert end >= start and use max(1, (end - start).days) only if same-day accrual rules permit.","Validate all three simple_interest arguments together before calling (see defense snippet)."],"exampleFix":"# before\nsi = simple_interest(5500.0, 0.01, -5)  # ValueError\n\n# after\nfrom datetime import date\ndays = (date(2024, 2, 1) - date(2024, 1, 1)).days  # 31\nsi = simple_interest(5500.0, 0.01, days)","handlingStrategy":"validation","validationCode":"if days_between_payments <= 0:\n    raise ScheduleError(\"days_between_payments must be > 0; check payment date order\")","typeGuard":"def valid_simple_interest_args(p, r, d) -> bool:\n    return p > 0 and r >= 0 and d > 0","tryCatchPattern":"try:\n    si = simple_interest(principal, daily_rate, days)\nexcept ValueError as exc:\n    raise ScheduleError(str(exc)) from exc","preventionTips":["Assert payment date > loan date before computing day deltas.","Validate the whole (principal, rate, days) triple in one pre-check.","Watch timezone shifts collapsing day counts to 0."],"tags":["finance","interest","validation","dates"],"backgroundTag":null,"analyzedSha":"f5988cc09713315817df6a7e327e258013a94440","analyzedAt":"2026-08-14T17:30:07.041Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}