Skip to content

Commit 859e9a6

Browse files
Raise ValueError for invalid A1Z26 input
1 parent 25bcced commit 859e9a6

1 file changed

Lines changed: 20 additions & 1 deletion

File tree

ciphers/a1z26.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,32 @@
77
"""
88

99
from __future__ import annotations
10-
10+
import string
1111

1212
def encode(plain: str) -> list[int]:
1313
"""
1414
>>> encode("myname")
1515
[13, 25, 14, 1, 13, 5]
16+
17+
>>> encode("")
18+
Traceback (most recent call last):
19+
...
20+
ValueError: Input must contain only lowercase letters a-z.
21+
22+
>>> encode("HELLO")
23+
Traceback (most recent call last):
24+
...
25+
ValueError: Input must contain only lowercase letters a-z.
26+
27+
>>> encode("hi there")
28+
Traceback (most recent call last):
29+
...
30+
ValueError: Input must contain only lowercase letters a-z.
1631
"""
32+
33+
if not plain or any(ch not in string.ascii_lowercase for ch in plain):
34+
raise ValueError("Input must contain only lowercase letters a-z.")
35+
1736
return [ord(elem) - 96 for elem in plain]
1837

1938

0 commit comments

Comments
 (0)