File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 88
99from __future__ import annotations
1010
11+ import string
12+
1113
1214def encode (plain : str ) -> list [int ]:
1315 """
1416 >>> encode("myname")
1517 [13, 25, 14, 1, 13, 5]
18+
19+ >>> encode("")
20+ Traceback (most recent call last):
21+ ...
22+ ValueError: Input must contain only lowercase letters a-z.
23+
24+ >>> encode("HELLO")
25+ Traceback (most recent call last):
26+ ...
27+ ValueError: Input must contain only lowercase letters a-z.
28+
29+ >>> encode("hi there")
30+ Traceback (most recent call last):
31+ ...
32+ ValueError: Input must contain only lowercase letters a-z.
1633 """
34+
35+ if not plain or any (ch not in string .ascii_lowercase for ch in plain ):
36+ raise ValueError ("Input must contain only lowercase letters a-z." )
37+
1738 return [ord (elem ) - 96 for elem in plain ]
1839
1940
You can’t perform that action at this time.
0 commit comments