{"record":{"id":"5ac2e7050e673c3c","repo":"TheAlgorithms/Python","slug":"plain-must-contain-only-lowercase-letters-a-z","errorCode":null,"errorMessage":"plain must contain only lowercase letters (a-z)","messagePattern":"plain must contain only lowercase letters \\(a-z\\)","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"ciphers/a1z26.py","lineNumber":30,"sourceCode":"def encode(plain: str) -> list[int]:\n    \"\"\"\n    >>> encode(\"myname\")\n    [13, 25, 14, 1, 13, 5]\n    >>> encode(\"abCd\")\n    Traceback (most recent call last):\n        ...\n    ValueError: plain must contain only lowercase letters (a-z)\n    >>> encode(\"n0w\")\n    Traceback (most recent call last):\n        ...\n    ValueError: plain must contain only lowercase letters (a-z)\n    >>> encode(\"later!\")\n    Traceback (most recent call last):\n        ...\n    ValueError: plain must contain only lowercase letters (a-z)\n    \"\"\"\n    if not plain.islower() or not plain.isalpha():\n        raise ValueError(\"plain must contain only lowercase letters (a-z)\")\n    return [ord(elem) - 96 for elem in plain]\n\n\ndef decode(encoded: list[int]) -> str:\n    \"\"\"\n    >>> decode([13, 25, 14, 1, 13, 5])\n    'myname'\n    \"\"\"\n    return \"\".join(chr(elem + 96) for elem in encoded)\n\n\ndef main() -> None:\n    encoded = encode(input(\"-> \").strip().lower())\n    print(\"Encoded: \", encoded)\n    print(\"Decoded:\", decode(encoded))\n\n\nif __name__ == \"__main__\":","sourceCodeStart":12,"sourceCodeEnd":48,"githubUrl":"https://github.com/TheAlgorithms/Python/blob/f5988cc09713315817df6a7e327e258013a94440/ciphers/a1z26.py#L12-L48","documentation":"Raised by a1z26 encode() when the plaintext contains anything besides lowercase letters — uppercase letters, digits, punctuation, or spaces all fail. The check `not plain.islower() or not plain.isalpha()` requires the string to be entirely a-z, because the cipher maps each character via ord(elem) - 96 to its alphabet position (a=1..z=26).","triggerScenarios":"Calling encode('Hello'), encode('n0w'), or encode('later!') as in the doctests. Any space also fails, since isalpha() is False for spaces.","commonSituations":"Feeding raw user sentences (capitalized or with punctuation) without preprocessing, or assuming the cipher handles spaces like other classical ciphers in the repo do.","solutions":["Normalize input first: plain = plain.lower() and strip non-letters, e.g. ''.join(c for c in text.lower() if c.isalpha()).","If spaces must be preserved, use a different cipher from the repo or extend encode() yourself.","Reject early with a clear message in your own input pipeline rather than relying on the traceback."],"exampleFix":"# before\nencode('later!')  # ValueError: plain must contain only lowercase letters (a-z)\n\n# after\nencode(''.join(c for c in 'later!'.lower() if c.isalpha()))  # [12,1,20,5,18]","handlingStrategy":"validation","validationCode":"plain = ''.join(c for c in text.lower() if c.isalpha())\nif not plain:\n    raise ValueError('no letters to encode')","typeGuard":"def is_all_lowercase_alpha(s: str) -> bool:\n    return s.isalpha() and s.islower()","tryCatchPattern":"try:\n    encode(plain)\nexcept ValueError as e:\n    if 'lowercase' in str(e):\n        plain = ''.join(c for c in plain.lower() if c.isalpha())\n        encode(plain)","preventionTips":["Lowercase + strip non-letters before calling a1z26 encode.","Remember spaces are NOT allowed in this cipher, unlike some others in the repo."],"tags":["cipher","validation","python"],"backgroundTag":null,"analyzedSha":"f5988cc09713315817df6a7e327e258013a94440","analyzedAt":"2026-08-14T17:30:07.041Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}