Skip to content

Commit cb237ed

Browse files
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent ea72a2c commit cb237ed

2 files changed

Lines changed: 32 additions & 23 deletions

File tree

strings/Secret_language.py

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -3,51 +3,60 @@
33
import random
44
import string
55

6+
67
def random_chars() -> str:
7-
'''
8+
"""
89
Adds random 3 charaters to the string.
9-
10-
'''
11-
return ''.join(random.choices(string.ascii_letters, k=3))
10+
11+
"""
12+
return "".join(random.choices(string.ascii_letters, k=3))
13+
1214

1315
def random_digits() -> str:
14-
'''
16+
"""
1517
Adds 3 random digits to the string.
16-
'''
17-
18-
return ''.join(random.choices(string.digits, k=3))
18+
"""
19+
20+
return "".join(random.choices(string.digits, k=3))
21+
1922

2023
def encode(code) -> str:
21-
'''
24+
"""
2225
Encodes the code by shifting the first character to the end of the original string,
2326
and adding the 3 random_characters + 3 random-digits + original string(code) + 3 random-digits + 3 random_characters.
24-
unless the length of the code exceeds 3 or equals to it.'''
25-
27+
unless the length of the code exceeds 3 or equals to it."""
28+
2629
if len(code) >= 3:
2730
code = code[1:] + code[0]
28-
code = random_chars() + random_digits() + code + random_digits() + random_chars()
31+
code = (
32+
random_chars() + random_digits() + code + random_digits() + random_chars()
33+
)
2934
else:
3035
code = code[::-1]
31-
code = random_chars() + random_digits() + code + random_digits() + random_chars()
36+
code = (
37+
random_chars() + random_digits() + code + random_digits() + random_chars()
38+
)
3239
return code
3340

41+
3442
def decode(code) -> str:
35-
'''
43+
"""
3644
decodes the encoded string by removing the randomly added characters and reversing the shift
37-
38-
'''
39-
45+
46+
"""
47+
4048
code = code[6:-6]
4149
if len(code) >= 3:
4250
code = code[-1] + code[:-1]
4351
else:
4452
code = code[::-1]
4553
return code
4654

55+
4756
if __name__ == "__main__":
4857
code = input("Enter the code: ")
4958
encoded = encode(code)
50-
decoded = decode(encoded)
59+
decoded = decode(encoded)
5160
print(f"Original → {code}")
5261
print(f"Encoded → {encoded}")
53-
print(f"Decoded → {decoded}")
62+
print(f"Decoded → {decoded}")

strings/frequency_finder.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,9 @@
3636

3737

3838
def get_letter_count(message: str) -> dict[str, int]:
39-
'''get_letter_count() is a function that takes message as parameter which is
40-
supposed to be the string. and it returns a dictionary where string is a key
41-
and integer is a value.'''
39+
"""get_letter_count() is a function that takes message as parameter which is
40+
supposed to be the string. and it returns a dictionary where string is a key
41+
and integer is a value."""
4242
letter_count = dict.fromkeys(string.ascii_uppercase, 0)
4343
for letter in message.upper():
4444
if letter in LETTERS:
@@ -48,7 +48,7 @@ def get_letter_count(message: str) -> dict[str, int]:
4848

4949

5050
def get_item_at_index_zero(x: tuple) -> str:
51-
'''It takes x as parameter which is tuple and returns a string.'''
51+
"""It takes x as parameter which is tuple and returns a string."""
5252
return x[0]
5353

5454

0 commit comments

Comments
 (0)