{"record":{"id":"3f3ac2a07865f3c9","repo":"TheAlgorithms/Python","slug":"input-value-is-not-an-integer","errorCode":null,"errorMessage":"Input value is not an integer","messagePattern":"Input value is not an integer","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"conversions/decimal_to_binary.py","lineNumber":100,"sourceCode":"    '0b101000'\n    >>> decimal_to_binary_recursive(-40)\n    '-0b101000'\n    >>> decimal_to_binary_recursive(40.8)\n    Traceback (most recent call last):\n        ...\n    ValueError: Input value is not an integer\n    >>> decimal_to_binary_recursive(\"forty\")\n    Traceback (most recent call last):\n        ...\n    ValueError: Input value is not an integer\n    \"\"\"\n    number = str(number).strip()\n    if not number:\n        raise ValueError(\"No input value was provided\")\n    negative = \"-\" if number.startswith(\"-\") else \"\"\n    number = number.lstrip(\"-\")\n    if not number.isnumeric():\n        raise ValueError(\"Input value is not an integer\")\n    return f\"{negative}0b{decimal_to_binary_recursive_helper(int(number))}\"\n\n\nif __name__ == \"__main__\":\n    import doctest\n\n    doctest.testmod()\n\n    print(decimal_to_binary_recursive(input(\"Input a decimal number: \")))\n","sourceCodeStart":82,"sourceCodeEnd":110,"githubUrl":"https://github.com/TheAlgorithms/Python/blob/f5988cc09713315817df6a7e327e258013a94440/conversions/decimal_to_binary.py#L82-L110","documentation":"Raised by decimal_to_binary_recursive(number) in conversions/decimal_to_binary.py:100 when the (sign-stripped) input fails str.isnumeric() — i.e. it is not composed purely of digit characters. After str(number).strip() and lstrip('-'), anything left over that is not numeric (letters, '40.8' with a dot, hex strings) is rejected with a ValueError before recursion starts.","triggerScenarios":"decimal_to_binary_recursive('forty'), decimal_to_binary_recursive(40.8) (str(40.8) = '40.8' contains '.'), decimal_to_binary_recursive('0x1F'), or inputs with spaces, commas, plus signs, or underscores.","commonSituations":"Passing floats directly — a frequent surprise since 40.8 stringifies to '40.8' and the dot fails isnumeric(); accepting free-text numeric input; localized numbers using ',' decimal separators.","solutions":["For floats, convert to int explicitly first: decimal_to_binary_recursive(int(40.8)) (truncates) or round()","Restrict input to integer strings: strip whitespace, verify with s.lstrip('-').isnumeric() before calling","For hex/binary source strings, parse with int(s, 16)/int(s, 2) first, then pass the int"],"exampleFix":"# before\ndecimal_to_binary_recursive(40.8)  # ValueError\n\n# after\ndecimal_to_binary_recursive(int(40.8))  # '0b101000'","handlingStrategy":"validation","validationCode":"s = str(number).strip().lstrip('-')\nif not s.isnumeric():\n    raise ValueError(f'{number!r} is not an integer')\n# floats: use int(number) first if fractional part should be truncated","typeGuard":null,"tryCatchPattern":"try:\n    decimal_to_binary_recursive(number)\nexcept ValueError:\n    number = int(float(number))  # last-resort coercion for numeric strings/floats\n    result = decimal_to_binary_recursive(number)","preventionTips":["Never pass raw floats — coerce with int()/round() and decide truncation policy","Reject hex/binary source strings or parse them with int(s, base) first","Strip whitespace and normalize localization (commas) before calling"],"tags":["python","value-error","binary","input-validation"],"backgroundTag":null,"analyzedSha":"f5988cc09713315817df6a7e327e258013a94440","analyzedAt":"2026-08-14T17:30:07.041Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}