{"record":{"id":"2ea73eb908542521","repo":"TheAlgorithms/Python","slug":"solution-only-accepts-values-from-0-to-100","errorCode":null,"errorMessage":"solution() only accepts values from 0 to 100","messagePattern":"solution\\(\\) only accepts values from 0 to 100","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"project_euler/problem_112/sol1.py","lineNumber":75,"sourceCode":"    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\n    ValueError: solution() only accepts values from 0 to 100\r\n    >>> solution(100.011)\r\n    Traceback (most recent call last):\r\n        ...\r\n    ValueError: solution() only accepts values from 0 to 100\r\n    \"\"\"\r\n    if not 0 < percent < 100:\r\n        raise ValueError(\"solution() only accepts values from 0 to 100\")\r\n    bouncy_num = 0\r\n    num = 1\r\n\r\n    while True:\r\n        if check_bouncy(num):\r\n            bouncy_num += 1\r\n        if (bouncy_num / num) * 100 >= percent:\r\n            return num\r\n        num += 1\r\n\r\n\r\nif __name__ == \"__main__\":\r\n    from doctest import testmod\r\n\r\n    testmod()\r\n    print(f\"{solution(99)}\")\r\n","sourceCodeStart":57,"sourceCodeEnd":92,"githubUrl":"https://github.com/TheAlgorithms/Python/blob/f5988cc09713315817df6a7e327e258013a94440/project_euler/problem_112/sol1.py#L57-L92","documentation":"Raised by solution() in project_euler/problem_112/sol1.py when percent is not strictly between 0 and 100 (check: not 0 < percent < 100). The function searches for the least number whose bouncy proportion reaches percent, which is only well-defined inside the open interval; 0, 100, and out-of-range values are rejected. Floats are accepted here, unlike the int-only helpers.","triggerScenarios":"solution(105), solution(100.011), solution(0), solution(100), solution(-5). Note the endpoints themselves are rejected: solution(100) raises even though 100 looks reasonable (the proportion never provably reaches exactly 100% in the incremental search).","commonSituations":"User-supplied percentage fields without range validation; passing 100 expecting 'all bouncy'; unit tests probing boundary values; sign errors or percent-vs-fraction confusion (passing 0.99 instead of 99).","solutions":["Pass a value strictly inside (0, 100), e.g. solution(99) for the canonical problem.","If your input is a fraction (0-1), multiply by 100 first: solution(frac * 100).","Validate range in your UI/config layer: if not 0 < pct < 100: reject.","For '100% bouncy' style requests, cap to 99.999 or handle as a special case outside this API."],"exampleFix":"# before\npct = 100  # user asked for 'all bouncy'\nsolution(pct)  # ValueError\n\n# after\npct = min(pct, 99.999)\nsolution(pct)","handlingStrategy":"validation","validationCode":"if not 0 < percent < 100:\n    raise ValueError(f\"percent must be in (0, 100) exclusive, got {percent}\")\nsolution(percent)","typeGuard":"def is_valid_percent(p) -> bool:\n    return isinstance(p, (int, float)) and 0 < p < 100","tryCatchPattern":"try:\n    num = solution(percent)\nexcept ValueError as e:\n    if \"0 to 100\" in str(e):\n        num = solution(min(max(percent, 0.001), 99.999))\n    else:\n        raise","preventionTips":["The interval is open: 0 and 100 are rejected; clamp inside (0, 100).","If your value is a fraction, multiply by 100 before calling.","Validate percentage fields in config/UI with an exclusive range."],"tags":["project-euler","validation","valueerror","range-check"],"backgroundTag":null,"analyzedSha":"f5988cc09713315817df6a7e327e258013a94440","analyzedAt":"2026-08-14T17:30:07.041Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}