File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 77"""
88
99from __future__ import annotations
10-
10+ import string
1111
1212def 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
You can’t perform that action at this time.
0 commit comments