{"record":{"id":"25ceb6867feb1c0d","repo":"TheAlgorithms/Python","slug":"invalid-numbering-system","errorCode":null,"errorMessage":"Invalid numbering system","messagePattern":"Invalid numbering system","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"conversions/convert_number_to_words.py","lineNumber":52,"sourceCode":"        \"\"\"\n        Gets the max value supported by the given number system.\n\n        >>> NumberingSystem.max_value(\"short\") == 10**18 - 1\n        True\n        >>> NumberingSystem.max_value(\"long\") == 10**21 - 1\n        True\n        >>> NumberingSystem.max_value(\"indian\") == 10**19 - 1\n        True\n        \"\"\"\n        match system_enum := cls[system.upper()]:\n            case cls.SHORT:\n                max_exp = system_enum.value[0][0] + 3\n            case cls.LONG:\n                max_exp = system_enum.value[0][0] + 6\n            case cls.INDIAN:\n                max_exp = 19\n            case _:\n                raise ValueError(\"Invalid numbering system\")\n        return 10**max_exp - 1\n\n\nclass NumberWords(Enum):\n    ONES = {  # noqa: RUF012\n        0: \"\",\n        1: \"one\",\n        2: \"two\",\n        3: \"three\",\n        4: \"four\",\n        5: \"five\",\n        6: \"six\",\n        7: \"seven\",\n        8: \"eight\",\n        9: \"nine\",\n    }\n\n    TEENS = {  # noqa: RUF012","sourceCodeStart":34,"sourceCodeEnd":70,"githubUrl":"https://github.com/TheAlgorithms/Python/blob/f5988cc09713315817df6a7e327e258013a94440/conversions/convert_number_to_words.py#L34-L70","documentation":"NumberingSystem.max_value raises ValueError('Invalid numbering system') from the match statement's fallback case when the resolved enum member is neither SHORT, LONG, nor INDIAN. In practice an unknown system name (e.g. 'french') raises KeyError earlier at cls[system.upper()], so this ValueError mainly guards against future enum members added without a case — the reachable invalid-input error is the KeyError.","triggerScenarios":"convert_number(123, 'short') works; convert_number(123, 'metric') raises KeyError('METRIC') from the cls[...] lookup; the ValueError path requires an enum member outside the three cased members.","commonSituations":"Assuming arbitrary locale names ('us', 'uk', 'european') are accepted; passing the enum member itself instead of its name string; case is handled (.upper()) but aliases are not.","solutions":["Use one of the three accepted names: 'short', 'long', or 'indian'","Catch both KeyError and ValueError when system names come from user input","Validate against [e.name.lower() for e in NumberingSystem] before calling"],"exampleFix":"# before\nconvert_number(1234, 'european')\n\n# after\nconvert_number(1234, 'long')","handlingStrategy":"validation","validationCode":"VALID_SYSTEMS = {'short', 'long', 'indian'}\nif system.lower() not in VALID_SYSTEMS:\n    raise ValueError(f'system must be one of {sorted(VALID_SYSTEMS)}')","typeGuard":"def is_valid_system(name) -> bool:\n    return isinstance(name, str) and name.upper() in {'SHORT', 'LONG', 'INDIAN'}","tryCatchPattern":"try:\n    convert_number(n, system)\nexcept (KeyError, ValueError):\n    return convert_number(n, 'short')  # fallback system","preventionTips":["Offer a fixed dropdown of the three system names","Remember invalid names raise KeyError, not ValueError","Centralize system-name normalization in one helper"],"tags":["conversions","numbers-to-words","validation","enum"],"backgroundTag":null,"analyzedSha":"f5988cc09713315817df6a7e327e258013a94440","analyzedAt":"2026-08-14T17:30:07.041Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}