{"record":{"id":"fb401550d7d2c68b","repo":"TheAlgorithms/Python","slug":"check-bouncy-accepts-only-integer-arguments","errorCode":null,"errorMessage":"check_bouncy() accepts only integer arguments","messagePattern":"check_bouncy\\(\\) accepts only integer arguments","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"project_euler/problem_112/sol1.py","lineNumber":49,"sourceCode":"        ...\r\n    ValueError: check_bouncy() accepts only integer arguments\r\n    >>> check_bouncy(132475)\r\n    True\r\n    >>> check_bouncy(34)\r\n    False\r\n    >>> check_bouncy(341)\r\n    True\r\n    >>> check_bouncy(47)\r\n    False\r\n    >>> check_bouncy(-12.54)\r\n    Traceback (most recent call last):\r\n        ...\r\n    ValueError: check_bouncy() accepts only integer arguments\r\n    >>> check_bouncy(-6548)\r\n    True\r\n    \"\"\"\r\n    if not isinstance(n, int):\r\n        raise ValueError(\"check_bouncy() accepts only integer arguments\")\r\n    str_n = str(n)\r\n    sorted_str_n = \"\".join(sorted(str_n))\r\n    return str_n not in {sorted_str_n, sorted_str_n[::-1]}\r\n\r\n\r\ndef solution(percent: float = 99) -> int:\r\n    \"\"\"\r\n    Returns the least number for which the proportion of bouncy numbers is\r\n    exactly 'percent'\r\n    >>> solution(50)\r\n    538\r\n    >>> solution(90)\r\n    21780\r\n    >>> solution(80)\r\n    4770\r\n    >>> solution(105)\r\n    Traceback (most recent call last):\r\n        ...\r","sourceCodeStart":31,"sourceCodeEnd":67,"githubUrl":"https://github.com/TheAlgorithms/Python/blob/f5988cc09713315817df6a7e327e258013a94440/project_euler/problem_112/sol1.py#L31-L67","documentation":"Raised by check_bouncy() in project_euler/problem_112/sol1.py when n is not an int instance. The function stringifies n and compares against its sorted characters, which is only meaningful for integers; floats and strings are rejected. Note the exception is ValueError, not TypeError, despite being a type check.","triggerScenarios":"check_bouncy(-12.54) (the doctest case), check_bouncy(\"341\"), check_bouncy(3.0), check_bouncy(None). Booleans pass because bool subclasses int.","commonSituations":"Counting loops that mix float arithmetic into the counter; values from pandas/numpy columns; stringified numbers from text processing.","solutions":["Pass plain ints: check_bouncy(341).","Keep loop counters as ints; never divide-and-reassign the counter itself.","Convert numeric inputs once at the boundary: n = int(n) after an integrality check."],"exampleFix":"# before\nnum = 1.0  # float seed\nwhile ...:\n    check_bouncy(num)  # ValueError once reached\n    num += 1\n\n# after\nnum = 1  # int seed","handlingStrategy":"type-guard","validationCode":"if not isinstance(n, int) or isinstance(n, bool):\n    raise ValueError(f\"check_bouncy needs int, got {type(n).__name__}\")\ncheck_bouncy(n)","typeGuard":"def is_plain_int(value) -> bool:\n    return isinstance(value, int) and not isinstance(value, bool)","tryCatchPattern":"try:\n    bouncy = check_bouncy(num)\nexcept ValueError as e:\n    if \"integer arguments\" in str(e):\n        bouncy = check_bouncy(int(num))\n    else:\n        raise","preventionTips":["Seed counters as int (1, not 1.0) and never reassign them float expressions.","Convert numpy/pandas values with int() before calling.","It is raised as ValueError though it is a type check; match message text if branching."],"tags":["project-euler","type-check","valueerror","input-validation"],"backgroundTag":null,"analyzedSha":"f5988cc09713315817df6a7e327e258013a94440","analyzedAt":"2026-08-14T17:30:07.041Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}