{"record":{"id":"a1d3513986618f62","repo":"TheAlgorithms/Python","slug":"the-parameter-costs-should-be-a-list-of-three-inte","errorCode":null,"errorMessage":"The parameter costs should be a list of three integers","messagePattern":"The parameter costs should be a list of three integers","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"dynamic_programming/minimum_tickets_cost.py","lineNumber":96,"sourceCode":"    ValueError: The parameter costs should be a list of three integers\n\n    >>> mincost_tickets([], [])\n    Traceback (most recent call last):\n     ...\n    ValueError: The parameter costs should be a list of three integers\n\n    >>> mincost_tickets([2, 3, 4, 5, 6, 7, 8, 9, 10, 30, 31], [1, 2, 3, 4])\n    Traceback (most recent call last):\n     ...\n    ValueError: The parameter costs should be a list of three integers\n    \"\"\"\n\n    # Validation\n    if not isinstance(days, list) or not all(isinstance(day, int) for day in days):\n        raise ValueError(\"The parameter days should be a list of integers\")\n\n    if len(costs) != 3 or not all(isinstance(cost, int) for cost in costs):\n        raise ValueError(\"The parameter costs should be a list of three integers\")\n\n    if len(days) == 0:\n        return 0\n\n    if min(days) <= 0:\n        raise ValueError(\"All days elements should be greater than 0\")\n\n    if max(days) >= 366:\n        raise ValueError(\"All days elements should be less than 366\")\n\n    days_set = set(days)\n\n    @functools.cache\n    def dynamic_programming(index: int) -> int:\n        if index > 365:\n            return 0\n\n        if index not in days_set:","sourceCodeStart":78,"sourceCodeEnd":114,"githubUrl":"https://github.com/TheAlgorithms/Python/blob/f5988cc09713315817df6a7e327e258013a94440/dynamic_programming/minimum_tickets_cost.py#L78-L114","documentation":"Raised by mincost_tickets() when the costs argument is not a list of exactly three integers. The function models LeetCode's 'Minimum Cost For Tickets' problem, where the three costs correspond to 1-day, 7-day, and 30-day pass prices. Any other length or non-int element (e.g. floats like 2.5) is rejected before the DP runs.","triggerScenarios":"Calling mincost_tickets(days, costs) with len(costs) != 3, e.g. mincost_tickets([1,2,3,4],[1,2,3,4]) (4 costs), or with float/string elements such as [1.5, 2, 3] or ['1','2','3']. Note bool passes isinstance(x, int) since bool subclasses int.","commonSituations":"Passing a generic price list from user input or a config file without slicing to three entries; loading costs from JSON where values deserialize as floats (e.g. [2.0, 7.0, 15.0]); misunderstanding the API as accepting arbitrary pass types.","solutions":["Pass exactly three integer costs in the order [1-day, 7-day, 30-day], e.g. mincost_tickets(days, [2, 7, 15]).","If costs come from JSON/float sources, convert each element: [int(c) for c in costs] and verify len == 3 first.","Add a pre-call assertion or guard: assert len(costs) == 3 and all(isinstance(c, int) for c in costs)."],"exampleFix":"# before\nmincost_tickets([1, 4, 6, 7, 8, 20], [1.5, 7.0, 15.0])  # ValueError\n\n# after\ncosts = [int(c) for c in [1.5, 7.0, 15.0]]\nmincost_tickets([1, 4, 6, 7, 8, 20], costs)","handlingStrategy":"validation","validationCode":"def valid_costs(costs) -> bool:\n    return isinstance(costs, list) and len(costs) == 3 and all(\n        isinstance(c, int) and not isinstance(c, bool) for c in costs\n    )","typeGuard":"def is_cost_triple(costs: object) -> TypeGuard[list[int]]:\n    return isinstance(costs, list) and len(costs) == 3 and all(\n        type(c) is int for c in costs\n    )","tryCatchPattern":"try:\n    mincost_tickets(days, costs)\nexcept ValueError as e:\n    if 'three integers' in str(e):\n        costs = [int(round(c)) for c in costs[:3]]\n    else:\n        raise","preventionTips":["Normalize costs from JSON with [int(c) for c in costs] before calling.","Assert the 3-element shape at the system boundary.","Keep a single PASS_COSTS constant instead of building the list ad hoc."],"tags":["dynamic-programming","input-validation","valueerror"],"backgroundTag":null,"analyzedSha":"f5988cc09713315817df6a7e327e258013a94440","analyzedAt":"2026-08-14T17:30:07.041Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}