{"record":{"id":"c06077e2df184755","repo":"TheAlgorithms/Python","slug":"guess-value-must-be-within-the-range-of-lower-and","errorCode":null,"errorMessage":"guess value must be within the range of lower and higher value","messagePattern":"guess value must be within the range of lower and higher value","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"other/guess_the_number_search.py","lineNumber":117,"sourceCode":"    >>> guess_the_number(10, 1000, 5)\n    Traceback (most recent call last):\n        ...\n    ValueError: guess value must be within the range of lower and higher value\n\n    >>> guess_the_number(10000, 100, 5)\n    Traceback (most recent call last):\n        ...\n    ValueError: argument value for lower and higher must be(lower > higher)\n    \"\"\"\n    assert (\n        isinstance(lower, int) and isinstance(higher, int) and isinstance(to_guess, int)\n    ), 'argument values must be type of \"int\"'\n\n    if lower > higher:\n        raise ValueError(\"argument value for lower and higher must be(lower > higher)\")\n\n    if not lower < to_guess < higher:\n        raise ValueError(\n            \"guess value must be within the range of lower and higher value\"\n        )\n\n    def answer(number: int) -> str:\n        \"\"\"\n        Returns value by comparing with entered `to_guess` number\n        \"\"\"\n        if number > to_guess:\n            return \"high\"\n        elif number < to_guess:\n            return \"low\"\n        else:\n            return \"same\"\n\n    print(\"started...\")\n\n    last_lowest = lower\n    last_highest = higher","sourceCodeStart":99,"sourceCodeEnd":135,"githubUrl":"https://github.com/TheAlgorithms/Python/blob/f5988cc09713315817df6a7e327e258013a94440/other/guess_the_number_search.py#L99-L135","documentation":"Raised by guess_the_number when to_guess is not strictly inside the open interval (lower, higher). The search space of the binary search is [lower, higher], so the target must satisfy lower < to_guess < higher; endpoints themselves are rejected.","triggerScenarios":"Calling guess_the_number(10, 100, 10) or guess_the_number(10, 100, 100) (target equal to a bound), or to_guess outside the interval entirely, e.g. guess_the_number(10, 100, 500).","commonSituations":"Off-by-one mistakes where the target is generated with inclusive random.randint(lower, higher) and lands on an endpoint, or hard-coded puzzle answers that drift out of the configured range.","solutions":["Choose a target strictly between the bounds, e.g. random.randint(lower + 1, higher - 1)","Widen the bounds so the target is interior: lower < to_guess < higher","If endpoints must be guessable, note this API forbids them — pick a different target"],"exampleFix":"# before\nto_guess = random.randint(lower, higher)  # can equal a bound -> ValueError\nguess_the_number(lower, higher, to_guess)\n\n# after\nto_guess = random.randint(lower + 1, higher - 1)\nguess_the_number(lower, higher, to_guess)","handlingStrategy":"validation","validationCode":"def valid_target(lower: int, higher: int, to_guess: int) -> bool:\n    return lower < to_guess < higher  # strictly interior; endpoints rejected","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Generate targets with random.randint(lower + 1, higher - 1), never inclusive bounds","Assert the target is strictly inside the search interval in tests"],"tags":["argument-validation","range-check","game"],"backgroundTag":null,"analyzedSha":"f5988cc09713315817df6a7e327e258013a94440","analyzedAt":"2026-08-14T17:30:07.041Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}