From 1c2704e2817b6df64401a519a6cdf15fb567da1d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?G=C3=B6kay=20Sa=C4=9Flam?= Date: Sun, 26 Jul 2026 11:12:50 +0300 Subject: [PATCH] Raise ValueError for invalid A1Z26 input --- ciphers/a1z26.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/ciphers/a1z26.py b/ciphers/a1z26.py index a1377ea6d397..eb14b6a3fc1c 100644 --- a/ciphers/a1z26.py +++ b/ciphers/a1z26.py @@ -8,12 +8,33 @@ from __future__ import annotations +import string + def encode(plain: str) -> list[int]: """ >>> encode("myname") [13, 25, 14, 1, 13, 5] + + >>> encode("") + Traceback (most recent call last): + ... + ValueError: Input must contain only lowercase letters a-z. + + >>> encode("HELLO") + Traceback (most recent call last): + ... + ValueError: Input must contain only lowercase letters a-z. + + >>> encode("hi there") + Traceback (most recent call last): + ... + ValueError: Input must contain only lowercase letters a-z. """ + + if not plain or any(ch not in string.ascii_lowercase for ch in plain): + raise ValueError("Input must contain only lowercase letters a-z.") + return [ord(elem) - 96 for elem in plain]