{"record":{"id":"9637d7d2ab1582ac","repo":"TheAlgorithms/Python","slug":"parameter-number-must-be-greater-than-or-equal-to","errorCode":null,"errorMessage":"Parameter number must be greater than or equal to 0","messagePattern":"Parameter number must be greater than or equal to 0","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"project_euler/problem_074/sol2.py","lineNumber":66,"sourceCode":"        ...\n    TypeError: Parameter number must be int\n\n    >>> digit_factorial_sum(-1)\n    Traceback (most recent call last):\n        ...\n    ValueError: Parameter number must be greater than or equal to 0\n\n    >>> digit_factorial_sum(0)\n    1\n\n    >>> digit_factorial_sum(69)\n    363600\n    \"\"\"\n    if not isinstance(number, int):\n        raise TypeError(\"Parameter number must be int\")\n\n    if number < 0:\n        raise ValueError(\"Parameter number must be greater than or equal to 0\")\n\n    # Converts number in string to iterate on its digits and adds its factorial.\n    return sum(DIGIT_FACTORIAL[digit] for digit in str(number))\n\n\ndef solution(chain_length: int = 60, number_limit: int = 1000000) -> int:\n    \"\"\"\n    Returns the number of numbers below number_limit that produce chains with exactly\n    chain_length non repeating elements.\n\n    >>> solution(10.0, 1000)\n    Traceback (most recent call last):\n        ...\n    TypeError: Parameters chain_length and number_limit must be int\n\n    >>> solution(10, 1000.0)\n    Traceback (most recent call last):\n        ...","sourceCodeStart":48,"sourceCodeEnd":84,"githubUrl":"https://github.com/TheAlgorithms/Python/blob/f5988cc09713315817df6a7e327e258013a94440/project_euler/problem_074/sol2.py#L48-L84","documentation":"Raised by digit_factorial_sum() in project_euler/problem_074/sol2.py when number is a negative int. Digit factorial sums are only defined for non-negative integers (the doctest shows 0 -> 1 because 0! == 1), so negatives are rejected with ValueError after the isinstance check passes.","triggerScenarios":"digit_factorial_sum(-1), digit_factorial_sum(-50), or forwarding a loop variable that iterates into negatives (e.g. range(n, -1, -1) misuse).","commonSituations":"Buggy loop bounds in chain-length experiments (Project Euler 74 style); signed differences or deltas passed directly as the number; user input not clamped to >= 0.","solutions":["Pass number >= 0.","Fix loop bounds so the variable never goes negative.","Clamp or reject negatives before calling: if number < 0: skip/raise."],"exampleFix":"# before\nfor num in range(start, stop, -1):  # runs past 0\n    s = digit_factorial_sum(num)\n\n# after\nfor num in range(start, -1, -1):\n    s = digit_factorial_sum(num)","handlingStrategy":"validation","validationCode":"if number < 0:\n    raise ValueError(f\"number must be >= 0, got {number}\")\ndigit_factorial_sum(number)","typeGuard":"def is_non_negative_int(value) -> bool:\n    return isinstance(value, int) and value >= 0","tryCatchPattern":"try:\n    s = digit_factorial_sum(num)\nexcept ValueError:\n    logger.warning(\"negative input %d skipped\", num)\n    continue","preventionTips":["Check loop bounds never descend below 0.","Remember 0 is valid (returns 1, since 0! == 1).","Clamp signed values (deltas, differences) before passing."],"tags":["project-euler","validation","valueerror","loop-bounds"],"backgroundTag":null,"analyzedSha":"f5988cc09713315817df6a7e327e258013a94440","analyzedAt":"2026-08-14T17:30:07.041Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}