{"record":{"id":"49938f5e0eaebfba","repo":"TheAlgorithms/Python","slug":"parameter-number-must-be-int","errorCode":null,"errorMessage":"Parameter number must be int","messagePattern":"Parameter number must be int","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"project_euler/problem_074/sol2.py","lineNumber":63,"sourceCode":"\n    >>> digit_factorial_sum(69.0)\n    Traceback (most recent call last):\n        ...\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","sourceCodeStart":45,"sourceCodeEnd":81,"githubUrl":"https://github.com/TheAlgorithms/Python/blob/f5988cc09713315817df6a7e327e258013a94440/project_euler/problem_074/sol2.py#L45-L81","documentation":"Raised by digit_factorial_sum() in project_euler/problem_074/sol2.py when number is not an int instance. The function looks up each decimal digit in the DIGIT_FACTORIAL table via str(number); non-int types (float, str, Decimal) either index wrongly or defeat the isinstance contract, so a TypeError is raised first, before the negative check.","triggerScenarios":"digit_factorial_sum(\"69\"), digit_factorial_sum(69.0), digit_factorial_sum(3.14), digit_factorial_sum(None). Booleans pass the isinstance check since bool subclasses int.","commonSituations":"Feeding values that came through JSON or YAML (whole numbers parsed as float); passing a string of digits by mistake; numpy integer types in some configurations.","solutions":["Pass a plain int: digit_factorial_sum(69).","Coerce at the boundary: digit_factorial_sum(int(value)) after confirming value is integral (value == int(value)).","Reject strings explicitly rather than relying on the library's TypeError."],"exampleFix":"# before\nvalue = 69.0\ndigit_factorial_sum(value)  # TypeError\n\n# after\nassert float(value).is_integer()\ndigit_factorial_sum(int(value))","handlingStrategy":"type-guard","validationCode":"if not isinstance(number, int) or isinstance(number, bool):\n    raise TypeError(f\"number must be int, got {type(number).__name__}\")\ndigit_factorial_sum(number)","typeGuard":"def is_plain_int(value) -> bool:\n    return isinstance(value, int) and not isinstance(value, bool)","tryCatchPattern":"try:\n    s = digit_factorial_sum(number)\nexcept TypeError:\n    s = digit_factorial_sum(int(number))  # only if number was numeric\nexcept ValueError:\n    raise  # negative input; fix the caller","preventionTips":["Convert float-sourced values with an integrality assertion before calling.","Exclude bool if it should not count as int in your domain.","Keep chain experiments (problem 74) entirely in int arithmetic."],"tags":["project-euler","type-check","typeerror","input-validation"],"backgroundTag":null,"analyzedSha":"f5988cc09713315817df6a7e327e258013a94440","analyzedAt":"2026-08-14T17:30:07.041Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}