{"record":{"id":"b5c402ea36ee3a57","repo":"TheAlgorithms/Python","slug":"argument-value-for-lower-and-higher-must-be-lower","errorCode":null,"errorMessage":"argument value for lower and higher must be(lower > higher)","messagePattern":"argument value for lower and higher must be\\(lower > higher\\)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"other/guess_the_number_search.py","lineNumber":114,"sourceCode":"        ...\n    AssertionError: argument values must be type of \"int\"\n\n    >>> 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...\")","sourceCodeStart":96,"sourceCodeEnd":132,"githubUrl":"https://github.com/TheAlgorithms/Python/blob/f5988cc09713315817df6a7e327e258013a94440/other/guess_the_number_search.py#L96-L132","documentation":"Raised by guess_the_number when the lower bound exceeds the higher bound, since the binary search between lower and higher requires a well-ordered interval. The check runs after the type assert and before the to_guess range check.","triggerScenarios":"Calling guess_the_number(100, 10, 5) — i.e. lower=100, higher=10 — or any invocation with lower > higher.","commonSituations":"Swapping the two bound arguments positionally, or deriving bounds from user input / a config where the order is not enforced.","solutions":["Pass the smaller bound first: guess_the_number(lower, higher, to_guess) with lower <= higher","Validate/swap bounds before the call: if lower > higher: lower, higher = higher, lower"],"exampleFix":"# before\nguess_the_number(100, 10, 5)  # lower=100 > higher=10 -> ValueError\n\n# after\nguess_the_number(10, 100, 5)","handlingStrategy":"validation","validationCode":"def valid_range(lower: int, higher: int) -> bool:\n    return lower <= higher","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Pass lower/higher as keyword arguments to avoid positional swaps","Swap bounds defensively before calling range-based APIs"],"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"}