Skip to content

Commit 714b8b9

Browse files
committed
made some changes
2 parents cb408bf + cb237ed commit 714b8b9

2 files changed

Lines changed: 40 additions & 21 deletions

File tree

strings/Secret_language.py

Lines changed: 36 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,51 +3,70 @@
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))
1921

22+
23+
<<<<<<< HEAD
2024
def encode(code: str) -> str:
2125
'''
26+
=======
27+
def encode(code) -> str:
28+
"""
29+
>>>>>>> cb237ed2095a60e62d73afd8b17c1207cc1fb4f9
2230
Encodes the code by shifting the first character to the end of the original string,
2331
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-
32+
unless the length of the code exceeds 3 or equals to it."""
33+
2634
if len(code) >= 3:
2735
code = code[1:] + code[0]
28-
code = random_chars() + random_digits() + code + random_digits() + random_chars()
36+
code = (
37+
random_chars() + random_digits() + code + random_digits() + random_chars()
38+
)
2939
else:
3040
code = code[::-1]
31-
code = random_chars() + random_digits() + code + random_digits() + random_chars()
41+
code = (
42+
random_chars() + random_digits() + code + random_digits() + random_chars()
43+
)
3244
return code
3345
46+
<<<<<<< HEAD
3447
def decode(code: str) -> str:
3548
'''
49+
=======
50+
51+
def decode(code) -> str:
52+
"""
53+
>>>>>>> cb237ed2095a60e62d73afd8b17c1207cc1fb4f9
3654
decodes the encoded string by removing the randomly added characters and reversing the shift
37-
38-
'''
39-
55+
56+
"""
57+
4058
code = code[6:-6]
4159
if len(code) >= 3:
4260
code = code[-1] + code[:-1]
4361
else:
4462
code = code[::-1]
4563
return code
4664

65+
4766
if __name__ == "__main__":
4867
code = input("Enter the code: ")
4968
encoded = encode(code)
50-
decoded = decode(encoded)
69+
decoded = decode(encoded)
5170
print(f"Original → {code}")
5271
print(f"Encoded → {encoded}")
53-
print(f"Decoded → {decoded}")
72+
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)