Skip to content

Commit 01ce7eb

Browse files
committed
modified the file
1 parent 6541869 commit 01ce7eb

1 file changed

Lines changed: 14 additions & 21 deletions

File tree

strings/secret_language.py

Lines changed: 14 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,10 @@ def random_chars() -> str:
99
Generate a random string of 3 ASCII letters.
1010
1111
>>> import random
12-
>>> random.seed(42)
13-
>>> random_chars()
14-
'ZoX'
12+
>>> len(random_chars()) == 3
13+
True
14+
>>> all(c in string.ascii_letters for c in random_chars())
15+
True
1516
"""
1617
return ''.join(random.choices(string.ascii_letters, k=3))
1718

@@ -20,10 +21,10 @@ def random_digits() -> str:
2021
"""
2122
Generate a random string of 3 digits.
2223
23-
>>> import random
24-
>>> random.seed(42)
25-
>>> random_digits()
26-
'638'
24+
>>> len(random_digits()) == 3
25+
True
26+
>>> all(c in string.digits for c in random_digits())
27+
True
2728
"""
2829
return ''.join(random.choices(string.digits, k=3))
2930

@@ -35,15 +36,10 @@ def encode(code: str) -> str:
3536
3637
Reference: https://en.wikipedia.org/wiki/Caesar_cipher
3738
38-
>>> import random
39-
>>> random.seed(42)
40-
>>> encode('hello')
41-
'ZoX638elloh415mJu'
42-
43-
>>> import random
44-
>>> random.seed(42)
45-
>>> encode('hi')
46-
'ZoX638ih415mJu'
39+
>>> len(encode('hello')) == len('hello') + 12
40+
True
41+
>>> len(encode('hi')) == len('hi') + 12
42+
True
4743
"""
4844
if len(code) >= 3:
4945
code = code[1:] + code[0]
@@ -59,15 +55,12 @@ def decode(code: str) -> str:
5955
Decode an encoded string by stripping the random padding and
6056
reversing the character shift.
6157
62-
>>> import random
63-
>>> random.seed(42)
6458
>>> decode(encode('hello'))
6559
'hello'
66-
67-
>>> import random
68-
>>> random.seed(42)
6960
>>> decode(encode('hi'))
7061
'hi'
62+
>>> decode(encode('python'))
63+
'python'
7164
"""
7265
code = code[6:-6]
7366
if len(code) >= 3:

0 commit comments

Comments
 (0)