From 00c22a34ddc2918a1d71ff00e36c341428067c05 Mon Sep 17 00:00:00 2001 From: yauchuscom Date: Sun, 16 May 2021 13:18:42 +0300 Subject: [PATCH 01/22] Added censor function --- strings/censor.py | 0 1 file changed, 0 insertions(+), 0 deletions(-) create mode 100644 strings/censor.py diff --git a/strings/censor.py b/strings/censor.py new file mode 100644 index 000000000000..e69de29bb2d1 From 419434471455e53287360d75fdd85fd949d24066 Mon Sep 17 00:00:00 2001 From: yauchuscom Date: Mon, 17 May 2021 17:35:32 +0300 Subject: [PATCH 02/22] Added censor code --- strings/censor.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/strings/censor.py b/strings/censor.py index e69de29bb2d1..cbdd948a9033 100644 --- a/strings/censor.py +++ b/strings/censor.py @@ -0,0 +1,11 @@ +txt = input("Please enter the text from which you would like to censor a certain word: \n") +word = input("Please enter the word you would like to be censored from the text: \n") +txt_lst = txt.split() +for word1 in txt_lst: + if word1 == word: + txt_lst[txt_lst.index(word1)] = "*" * len(word1) +txt = "" +for word1 in txt_lst: + txt += word1 + " " +txt = txt[:-1] +print(txt) \ No newline at end of file From e7d4102bbb5a90ea144f9a5880a92722dc5cd20e Mon Sep 17 00:00:00 2001 From: Margaret <62753112+meg-1@users.noreply.github.com> Date: Mon, 17 May 2021 17:40:48 +0300 Subject: [PATCH 03/22] Added comments to the code --- strings/censor.py | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/strings/censor.py b/strings/censor.py index cbdd948a9033..5c629cf79a18 100644 --- a/strings/censor.py +++ b/strings/censor.py @@ -1,11 +1,15 @@ txt = input("Please enter the text from which you would like to censor a certain word: \n") word = input("Please enter the word you would like to be censored from the text: \n") txt_lst = txt.split() + +#here we loop through a list which consists of words from the text we should censor for word1 in txt_lst: if word1 == word: txt_lst[txt_lst.index(word1)] = "*" * len(word1) txt = "" + +#here we combine all of the split words in txt_lst into one string for word1 in txt_lst: txt += word1 + " " txt = txt[:-1] -print(txt) \ No newline at end of file +print(txt) From 93bd4acf6b7eeb2a856319837c3f854f0a574a11 Mon Sep 17 00:00:00 2001 From: yauchuscom Date: Sat, 22 May 2021 13:34:28 +0300 Subject: [PATCH 04/22] modified censor function --- strings/censor.py | 27 +++++++++++++-------------- 1 file changed, 13 insertions(+), 14 deletions(-) diff --git a/strings/censor.py b/strings/censor.py index 5c629cf79a18..607dcd9a53d7 100644 --- a/strings/censor.py +++ b/strings/censor.py @@ -1,15 +1,14 @@ -txt = input("Please enter the text from which you would like to censor a certain word: \n") -word = input("Please enter the word you would like to be censored from the text: \n") -txt_lst = txt.split() +def censor(txt, word): + txt_lst = txt.split() + #here we loop through a list which consists of words from the text we should censor + for word1 in txt_lst: + if word1 == word: + txt_lst[txt_lst.index(word1)] = "*" * len(word1) + txt = "" + #here we combine all of the split words in txt_lst into one string + for word1 in txt_lst: + txt += word1 + " " + txt = txt[:-1] + print(txt) -#here we loop through a list which consists of words from the text we should censor -for word1 in txt_lst: - if word1 == word: - txt_lst[txt_lst.index(word1)] = "*" * len(word1) -txt = "" - -#here we combine all of the split words in txt_lst into one string -for word1 in txt_lst: - txt += word1 + " " -txt = txt[:-1] -print(txt) +censor("one two three", "one") \ No newline at end of file From b7142782ae3376c5e66f2adf025d8e4a57e3f0d7 Mon Sep 17 00:00:00 2001 From: yauchuscom Date: Sun, 1 Aug 2021 23:05:45 +0300 Subject: [PATCH 05/22] added decrypt function --- strings/decrypt.py | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 strings/decrypt.py diff --git a/strings/decrypt.py b/strings/decrypt.py new file mode 100644 index 000000000000..478226af5f17 --- /dev/null +++ b/strings/decrypt.py @@ -0,0 +1,27 @@ +def decrypt(txt, symbol): + #here we split the string we need to decypher into a list + txt_lst = txt.split() + res_str = "" + #we create a for loop which loops through the newly created list + for word1 in txt_lst: + #here we convert the current word we got through the loop into a list of charachters + word1_lst = list(word1) + #we loop through each charachter in the newly created list of charachters form the word we are looping throuh + for char1 in word1_lst: + #we set a condition, where if the symbol the loop is currently on corresponds to the symbol we need to remove, we stop on it and examine it + if char1 == symbol: + #we find the charachters index from the word + indx = word1.index(char1) + #we remove the list (the list which contains every element and characahter from the word we are looping throuh) element with the same index from the list. + word1_lst[indx] = "" + res_wrd = "" + #we loop throuh the list containing all the charachters from the word, and append those charachters to a new string + for char1 in word1_lst: + res_wrd += char1 + #here we add the newly created, decyphered word to a new string which will contain our full result + res_str += res_wrd + " " + res_str = res_str[:-1] + #and here we print out the final result + print(res_str) + +decrypt("o$ne t$wo three$", "$") \ No newline at end of file From c879c7f589a41cf9a669fda94a01c38afd04484b Mon Sep 17 00:00:00 2001 From: yauchuscom Date: Wed, 4 Aug 2021 14:24:38 +0300 Subject: [PATCH 06/22] added cypher and decypher functions, deleted censor and decrypt functions --- strings/cypher_txt.py | 51 +++++++++++++++++++++++++++++++++++++++++ strings/decypher_txt.py | 49 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 100 insertions(+) create mode 100644 strings/cypher_txt.py create mode 100644 strings/decypher_txt.py diff --git a/strings/cypher_txt.py b/strings/cypher_txt.py new file mode 100644 index 000000000000..45abc0896e94 --- /dev/null +++ b/strings/cypher_txt.py @@ -0,0 +1,51 @@ +def cypher_mesage(txt): + alphabet_lower = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'] + alphabet_upper = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', "X", 'Y', 'Z'] + + info = [] + for char in txt: + if (char.isalpha() == False): + info.append(2) + elif char.isupper() == True: + info.append(1) + else: + info.append(0) + + indx_lst=[] + for char in txt: + if (char.isalpha() == False): + indx_lst+=char + else: + if char.isupper() == True: + indx_lst.append(alphabet_upper.index(char)) + else: + indx_lst.append(alphabet_lower.index(char)) + + res_indx=[] + for char in indx_lst: + if type(char) == int: + if int(char) <= 2: + res_indx.append(26 + (int(char) - 3)) + else: + res_indx.append(int(char) - 3) + else: + res_indx+=char + + + res_str = "" + count = 0 + for char in res_indx: + if type(char) != int: + res_str += char + else: + if info[count] == 0: + res_str += str(alphabet_lower[int(char)]) + elif info[count] == 1: + res_str += str(alphabet_upper[int(char)]) + count+=1 + + print(res_str) + + + +code_mesage("xXyzabB!1234") \ No newline at end of file diff --git a/strings/decypher_txt.py b/strings/decypher_txt.py new file mode 100644 index 000000000000..509f9fc6963c --- /dev/null +++ b/strings/decypher_txt.py @@ -0,0 +1,49 @@ +def decode_mesage(txt): + alphabet_lower = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'] + alphabet_upper = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', "X", 'Y', 'Z'] + + info = [] + for char in txt: + if (char.isalpha() == False): + info.append(2) + elif char.isupper() == True: + info.append(1) + else: + info.append(0) + + indx_lst=[] + for char in txt: + if (char.isalpha() == False): + indx_lst+=char + else: + if char.isupper() == True: + indx_lst.append(alphabet_upper.index(char)) + else: + indx_lst.append(alphabet_lower.index(char)) + + res_indx=[] + for char in indx_lst: + if type(char) == int: + if int(char) >= 23: + res_indx.append((int(char) - 23)) + else: + res_indx.append(int(char) + 3) + else: + res_indx+=char + + + res_str = "" + count = 0 + for char in res_indx: + if type(char) != int: + res_str += char + else: + if info[count] == 0: + res_str += str(alphabet_lower[int(char)]) + elif info[count] == 1: + res_str += str(alphabet_upper[int(char)]) + count+=1 + + print(res_str) + +print(decode_mesage("xyzab!1234")) \ No newline at end of file From e60dd6f96a3ec55e4ba148e316859a8d6b829658 Mon Sep 17 00:00:00 2001 From: Margaret <62753112+meg-1@users.noreply.github.com> Date: Wed, 4 Aug 2021 14:36:05 +0300 Subject: [PATCH 07/22] Deleted decrypt.py --- strings/decrypt.py | 27 --------------------------- 1 file changed, 27 deletions(-) delete mode 100644 strings/decrypt.py diff --git a/strings/decrypt.py b/strings/decrypt.py deleted file mode 100644 index 478226af5f17..000000000000 --- a/strings/decrypt.py +++ /dev/null @@ -1,27 +0,0 @@ -def decrypt(txt, symbol): - #here we split the string we need to decypher into a list - txt_lst = txt.split() - res_str = "" - #we create a for loop which loops through the newly created list - for word1 in txt_lst: - #here we convert the current word we got through the loop into a list of charachters - word1_lst = list(word1) - #we loop through each charachter in the newly created list of charachters form the word we are looping throuh - for char1 in word1_lst: - #we set a condition, where if the symbol the loop is currently on corresponds to the symbol we need to remove, we stop on it and examine it - if char1 == symbol: - #we find the charachters index from the word - indx = word1.index(char1) - #we remove the list (the list which contains every element and characahter from the word we are looping throuh) element with the same index from the list. - word1_lst[indx] = "" - res_wrd = "" - #we loop throuh the list containing all the charachters from the word, and append those charachters to a new string - for char1 in word1_lst: - res_wrd += char1 - #here we add the newly created, decyphered word to a new string which will contain our full result - res_str += res_wrd + " " - res_str = res_str[:-1] - #and here we print out the final result - print(res_str) - -decrypt("o$ne t$wo three$", "$") \ No newline at end of file From b3e0cb8b88617b4e62f6993ce24b62231ef1817f Mon Sep 17 00:00:00 2001 From: Margaret <62753112+meg-1@users.noreply.github.com> Date: Wed, 4 Aug 2021 14:36:45 +0300 Subject: [PATCH 08/22] Deleted censor.py --- strings/censor.py | 14 -------------- 1 file changed, 14 deletions(-) delete mode 100644 strings/censor.py diff --git a/strings/censor.py b/strings/censor.py deleted file mode 100644 index 607dcd9a53d7..000000000000 --- a/strings/censor.py +++ /dev/null @@ -1,14 +0,0 @@ -def censor(txt, word): - txt_lst = txt.split() - #here we loop through a list which consists of words from the text we should censor - for word1 in txt_lst: - if word1 == word: - txt_lst[txt_lst.index(word1)] = "*" * len(word1) - txt = "" - #here we combine all of the split words in txt_lst into one string - for word1 in txt_lst: - txt += word1 + " " - txt = txt[:-1] - print(txt) - -censor("one two three", "one") \ No newline at end of file From 947f7d84c083e0ae941977c741d332e2b73d74c3 Mon Sep 17 00:00:00 2001 From: yauchuscom Date: Wed, 4 Aug 2021 14:44:20 +0300 Subject: [PATCH 09/22] edited the crypt and decrypt files --- strings/cypher_txt.py | 6 +----- strings/decypher_txt.py | 4 +--- 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/strings/cypher_txt.py b/strings/cypher_txt.py index 45abc0896e94..338d2ec33f43 100644 --- a/strings/cypher_txt.py +++ b/strings/cypher_txt.py @@ -44,8 +44,4 @@ def cypher_mesage(txt): res_str += str(alphabet_upper[int(char)]) count+=1 - print(res_str) - - - -code_mesage("xXyzabB!1234") \ No newline at end of file + print(res_str) \ No newline at end of file diff --git a/strings/decypher_txt.py b/strings/decypher_txt.py index 509f9fc6963c..2f13ddd9a7d4 100644 --- a/strings/decypher_txt.py +++ b/strings/decypher_txt.py @@ -44,6 +44,4 @@ def decode_mesage(txt): res_str += str(alphabet_upper[int(char)]) count+=1 - print(res_str) - -print(decode_mesage("xyzab!1234")) \ No newline at end of file + print(res_str) \ No newline at end of file From daf21ad821d5462d47160c4efd6ca1ce572c772b Mon Sep 17 00:00:00 2001 From: Margaret <62753112+meg-1@users.noreply.github.com> Date: Wed, 4 Aug 2021 14:55:21 +0300 Subject: [PATCH 10/22] Update cypher_txt.py --- strings/cypher_txt.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/strings/cypher_txt.py b/strings/cypher_txt.py index 45abc0896e94..5aaeb6d0994d 100644 --- a/strings/cypher_txt.py +++ b/strings/cypher_txt.py @@ -45,7 +45,3 @@ def cypher_mesage(txt): count+=1 print(res_str) - - - -code_mesage("xXyzabB!1234") \ No newline at end of file From d3d8b29926119eb2a8b6eee5ce8dbef7f16cd64b Mon Sep 17 00:00:00 2001 From: Margaret <62753112+meg-1@users.noreply.github.com> Date: Wed, 4 Aug 2021 15:18:15 +0300 Subject: [PATCH 11/22] Remove the endline in cypher.py --- strings/cypher_txt.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/strings/cypher_txt.py b/strings/cypher_txt.py index 5aaeb6d0994d..3c23571f906c 100644 --- a/strings/cypher_txt.py +++ b/strings/cypher_txt.py @@ -43,5 +43,3 @@ def cypher_mesage(txt): elif info[count] == 1: res_str += str(alphabet_upper[int(char)]) count+=1 - - print(res_str) From 752c197dba6f158115372cbbe967fd8353ff026f Mon Sep 17 00:00:00 2001 From: Margaret <62753112+meg-1@users.noreply.github.com> Date: Wed, 4 Aug 2021 15:19:33 +0300 Subject: [PATCH 12/22] Removed the print at the end of decypher.py --- strings/decypher_txt.py | 4 ---- 1 file changed, 4 deletions(-) diff --git a/strings/decypher_txt.py b/strings/decypher_txt.py index 509f9fc6963c..aa97ac834ac0 100644 --- a/strings/decypher_txt.py +++ b/strings/decypher_txt.py @@ -43,7 +43,3 @@ def decode_mesage(txt): elif info[count] == 1: res_str += str(alphabet_upper[int(char)]) count+=1 - - print(res_str) - -print(decode_mesage("xyzab!1234")) \ No newline at end of file From f72431b07dae6a172e84d6041547858c17a75f8b Mon Sep 17 00:00:00 2001 From: yauchuscom Date: Wed, 18 Aug 2021 18:26:33 +0300 Subject: [PATCH 13/22] added 4 new algorithms --- strings/censor.py | 14 +++++++++++ strings/code_message.py | 51 +++++++++++++++++++++++++++++++++++++++ strings/decode_message.py | 49 +++++++++++++++++++++++++++++++++++++ strings/decrypt.py | 27 +++++++++++++++++++++ 4 files changed, 141 insertions(+) create mode 100644 strings/censor.py create mode 100644 strings/code_message.py create mode 100644 strings/decode_message.py create mode 100644 strings/decrypt.py diff --git a/strings/censor.py b/strings/censor.py new file mode 100644 index 000000000000..2481dbc9b7a6 --- /dev/null +++ b/strings/censor.py @@ -0,0 +1,14 @@ +def censor(txt, word) -> str: + txt_lst = txt.split() + #here we loop through a list which consists of words from the text we should censor + for index, word1 in enumerate(txt_lst): + if word1 == word: + txt_lst[index] = "*" * len(word1) + txt = "" + #here we combine all of the split words in txt_lst into one string + for word1 in txt_lst: + txt += word1 + " " + txt = txt[:-1] + print(txt) + +censor("one two three", "one") \ No newline at end of file diff --git a/strings/code_message.py b/strings/code_message.py new file mode 100644 index 000000000000..340c922f9764 --- /dev/null +++ b/strings/code_message.py @@ -0,0 +1,51 @@ +def code_mesage(txt) -> str: + alphabet_lower = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'] + alphabet_upper = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', "X", 'Y', 'Z'] + + info = [] + for char in txt: + if (char.isalpha() == False): + info.append(2) + elif char.isupper() == True: + info.append(1) + else: + info.append(0) + + indx_lst=[] + for char in txt: + if (char.isalpha() == False): + indx_lst+=char + else: + if char.isupper() == True: + indx_lst.append(alphabet_upper.index(char)) + else: + indx_lst.append(alphabet_lower.index(char)) + + res_indx=[] + for char in indx_lst: + if type(char) == int: + if int(char) <= 2: + res_indx.append(26 + (int(char) - 3)) + else: + res_indx.append(int(char) - 3) + else: + res_indx+=char + + + res_str = "" + count = 0 + for char in res_indx: + if type(char) != int: + res_str += char + else: + if info[count] == 0: + res_str += str(alphabet_lower[int(char)]) + elif info[count] == 1: + res_str += str(alphabet_upper[int(char)]) + count+=1 + + print(res_str) + + + +code_mesage("abcde!1234") \ No newline at end of file diff --git a/strings/decode_message.py b/strings/decode_message.py new file mode 100644 index 000000000000..c229dd6a2882 --- /dev/null +++ b/strings/decode_message.py @@ -0,0 +1,49 @@ +def decode_mesage(txt) -> str: + alphabet_lower = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'] + alphabet_upper = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', "X", 'Y', 'Z'] + + info = [] + for char in txt: + if (char.isalpha() == False): + info.append(2) + elif char.isupper() == True: + info.append(1) + else: + info.append(0) + + indx_lst=[] + for char in txt: + if (char.isalpha() == False): + indx_lst+=char + else: + if char.isupper() == True: + indx_lst.append(alphabet_upper.index(char)) + else: + indx_lst.append(alphabet_lower.index(char)) + + res_indx=[] + for char in indx_lst: + if type(char) == int: + if int(char) >= 23: + res_indx.append((int(char) - 23)) + else: + res_indx.append(int(char) + 3) + else: + res_indx+=char + + + res_str = "" + count = 0 + for char in res_indx: + if type(char) != int: + res_str += char + else: + if info[count] == 0: + res_str += str(alphabet_lower[int(char)]) + elif info[count] == 1: + res_str += str(alphabet_upper[int(char)]) + count+=1 + + print(res_str) + +print(decode_mesage("xyzab!1234")) \ No newline at end of file diff --git a/strings/decrypt.py b/strings/decrypt.py new file mode 100644 index 000000000000..3cbacbce0284 --- /dev/null +++ b/strings/decrypt.py @@ -0,0 +1,27 @@ +def decrypt(txt, symbol) -> str: + #here we split the string we need to decypher into a list + txt_lst = txt.split() + res_str = "" + #we create a for loop which loops through the newly created list + for word1 in txt_lst: + #here we convert the current word we got through the loop into a list of charachters + word1_lst = list(word1) + #we loop through each charachter in the newly created list of charachters form the word we are looping throuh + for char1 in word1_lst: + #we set a condition, where if the symbol the loop is currently on corresponds to the symbol we need to remove, we stop on it and examine it + if char1 == symbol: + #we find the charachters index from the word + indx = word1.index(char1) + #we remove the list (the list which contains every element and characahter from the word we are looping throuh) element with the same index from the list. + word1_lst[indx] = "" + res_wrd = "" + #we loop throuh the list containing all the charachters from the word, and append those charachters to a new string + for char1 in word1_lst: + res_wrd += char1 + #here we add the newly created, decyphered word to a new string which will contain our full result + res_str += res_wrd + " " + res_str = res_str[:-1] + #and here we print out the final result + print(res_str) + +decrypt("o$ne t$wo three$", "$") \ No newline at end of file From 4c891f484ed772a554d00fdaa1aac0443dfc4a31 Mon Sep 17 00:00:00 2001 From: yauchuscom Date: Wed, 25 Aug 2021 14:44:17 +0300 Subject: [PATCH 14/22] added tests to the four files --- strings/censor.py | 36 ++++++++++++++++++++++++------------ strings/code_message.py | 15 ++++++++++++--- strings/decode_message.py | 13 ++++++++++++- strings/decrypt.py | 13 ++++++++++++- 4 files changed, 60 insertions(+), 17 deletions(-) diff --git a/strings/censor.py b/strings/censor.py index 2481dbc9b7a6..de3c0b076c8b 100644 --- a/strings/censor.py +++ b/strings/censor.py @@ -1,14 +1,26 @@ def censor(txt, word) -> str: - txt_lst = txt.split() - #here we loop through a list which consists of words from the text we should censor - for index, word1 in enumerate(txt_lst): - if word1 == word: - txt_lst[index] = "*" * len(word1) - txt = "" - #here we combine all of the split words in txt_lst into one string - for word1 in txt_lst: - txt += word1 + " " - txt = txt[:-1] - print(txt) + """ + >>> censor("one two three", "one") + *** two three + >>> censor("email, password", "password") + email, ******** + >>> censor("pin: 2536", "2536") + pin: **** -censor("one two three", "one") \ No newline at end of file + """ + + txt_lst = txt.split() + #here we loop through a list which consists of words from the text we should censor + for index, word1 in enumerate(txt_lst): + if word1 == word: + txt_lst[index] = "*" * len(word1) + txt = "" + #here we combine all of the split words in txt_lst into one string + for word1 in txt_lst: + txt += word1 + " " + txt = txt[:-1] + print(txt) + +if __name__ == "__main__": + import doctest + doctest.testmod() \ No newline at end of file diff --git a/strings/code_message.py b/strings/code_message.py index 340c922f9764..ca40530cda24 100644 --- a/strings/code_message.py +++ b/strings/code_message.py @@ -1,4 +1,13 @@ def code_mesage(txt) -> str: + """ + >>> code_mesage("Def") + Abc + >>> code_mesage("bcF") + yzC + >>> code_mesage("qva") + nsx + + """ alphabet_lower = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'] alphabet_upper = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', "X", 'Y', 'Z'] @@ -46,6 +55,6 @@ def code_mesage(txt) -> str: print(res_str) - - -code_mesage("abcde!1234") \ No newline at end of file +if __name__ == "__main__": + import doctest + doctest.testmod() \ No newline at end of file diff --git a/strings/decode_message.py b/strings/decode_message.py index c229dd6a2882..028bd2ff553e 100644 --- a/strings/decode_message.py +++ b/strings/decode_message.py @@ -1,4 +1,13 @@ def decode_mesage(txt) -> str: + """ + >>> decode_mesage("eFg") + hIj + >>> decode_mesage("yzC") + bcF + >>> decode_mesage("nsx") + qva + + """ alphabet_lower = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'] alphabet_upper = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', "X", 'Y', 'Z'] @@ -46,4 +55,6 @@ def decode_mesage(txt) -> str: print(res_str) -print(decode_mesage("xyzab!1234")) \ No newline at end of file +if __name__ == "__main__": + import doctest + doctest.testmod() \ No newline at end of file diff --git a/strings/decrypt.py b/strings/decrypt.py index 3cbacbce0284..6d824653e790 100644 --- a/strings/decrypt.py +++ b/strings/decrypt.py @@ -1,4 +1,13 @@ def decrypt(txt, symbol) -> str: + """ + >>> decrypt("o$ne", "$") + one + >>> decrypt("dec@rypt", "@") + decrypt + >>> decrypt("p#ython cod#e", "#") + python code + + """ #here we split the string we need to decypher into a list txt_lst = txt.split() res_str = "" @@ -24,4 +33,6 @@ def decrypt(txt, symbol) -> str: #and here we print out the final result print(res_str) -decrypt("o$ne t$wo three$", "$") \ No newline at end of file +if __name__ == "__main__": + import doctest + doctest.testmod() \ No newline at end of file From c600b10545bc6a070198950f614cef948a5fde44 Mon Sep 17 00:00:00 2001 From: yauchuscom Date: Wed, 25 Aug 2021 14:54:01 +0300 Subject: [PATCH 15/22] added type hints for the function variables --- strings/censor.py | 2 +- strings/code_message.py | 2 +- strings/decode_message.py | 2 +- strings/decrypt.py | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/strings/censor.py b/strings/censor.py index de3c0b076c8b..fe10a08c5bc4 100644 --- a/strings/censor.py +++ b/strings/censor.py @@ -1,4 +1,4 @@ -def censor(txt, word) -> str: +def censor(txt: str, word: str) -> str: """ >>> censor("one two three", "one") *** two three diff --git a/strings/code_message.py b/strings/code_message.py index ca40530cda24..cb8603329115 100644 --- a/strings/code_message.py +++ b/strings/code_message.py @@ -1,4 +1,4 @@ -def code_mesage(txt) -> str: +def code_mesage(txt: str) -> str: """ >>> code_mesage("Def") Abc diff --git a/strings/decode_message.py b/strings/decode_message.py index 028bd2ff553e..9c100f7c2ec7 100644 --- a/strings/decode_message.py +++ b/strings/decode_message.py @@ -1,4 +1,4 @@ -def decode_mesage(txt) -> str: +def decode_mesage(txt: str) -> str: """ >>> decode_mesage("eFg") hIj diff --git a/strings/decrypt.py b/strings/decrypt.py index 6d824653e790..3535d2443a2c 100644 --- a/strings/decrypt.py +++ b/strings/decrypt.py @@ -1,4 +1,4 @@ -def decrypt(txt, symbol) -> str: +def decrypt(txt: str, symbol: str) -> str: """ >>> decrypt("o$ne", "$") one From 7a909e24a5bb5ba2d9e3a8582cad346613b9b1c3 Mon Sep 17 00:00:00 2001 From: Margaret <62753112+meg-1@users.noreply.github.com> Date: Sat, 25 Dec 2021 14:49:16 +0200 Subject: [PATCH 16/22] Deleted decode message --- strings/decode_message.py | 60 --------------------------------------- 1 file changed, 60 deletions(-) delete mode 100644 strings/decode_message.py diff --git a/strings/decode_message.py b/strings/decode_message.py deleted file mode 100644 index 9c100f7c2ec7..000000000000 --- a/strings/decode_message.py +++ /dev/null @@ -1,60 +0,0 @@ -def decode_mesage(txt: str) -> str: - """ - >>> decode_mesage("eFg") - hIj - >>> decode_mesage("yzC") - bcF - >>> decode_mesage("nsx") - qva - - """ - alphabet_lower = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'] - alphabet_upper = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', "X", 'Y', 'Z'] - - info = [] - for char in txt: - if (char.isalpha() == False): - info.append(2) - elif char.isupper() == True: - info.append(1) - else: - info.append(0) - - indx_lst=[] - for char in txt: - if (char.isalpha() == False): - indx_lst+=char - else: - if char.isupper() == True: - indx_lst.append(alphabet_upper.index(char)) - else: - indx_lst.append(alphabet_lower.index(char)) - - res_indx=[] - for char in indx_lst: - if type(char) == int: - if int(char) >= 23: - res_indx.append((int(char) - 23)) - else: - res_indx.append(int(char) + 3) - else: - res_indx+=char - - - res_str = "" - count = 0 - for char in res_indx: - if type(char) != int: - res_str += char - else: - if info[count] == 0: - res_str += str(alphabet_lower[int(char)]) - elif info[count] == 1: - res_str += str(alphabet_upper[int(char)]) - count+=1 - - print(res_str) - -if __name__ == "__main__": - import doctest - doctest.testmod() \ No newline at end of file From f5b5411a2126df879ed757bbd2944f54a41ccc23 Mon Sep 17 00:00:00 2001 From: Margaret <62753112+meg-1@users.noreply.github.com> Date: Sat, 25 Dec 2021 14:49:38 +0200 Subject: [PATCH 17/22] Deleted code message --- strings/code_message.py | 60 ----------------------------------------- 1 file changed, 60 deletions(-) delete mode 100644 strings/code_message.py diff --git a/strings/code_message.py b/strings/code_message.py deleted file mode 100644 index cb8603329115..000000000000 --- a/strings/code_message.py +++ /dev/null @@ -1,60 +0,0 @@ -def code_mesage(txt: str) -> str: - """ - >>> code_mesage("Def") - Abc - >>> code_mesage("bcF") - yzC - >>> code_mesage("qva") - nsx - - """ - alphabet_lower = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'] - alphabet_upper = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', "X", 'Y', 'Z'] - - info = [] - for char in txt: - if (char.isalpha() == False): - info.append(2) - elif char.isupper() == True: - info.append(1) - else: - info.append(0) - - indx_lst=[] - for char in txt: - if (char.isalpha() == False): - indx_lst+=char - else: - if char.isupper() == True: - indx_lst.append(alphabet_upper.index(char)) - else: - indx_lst.append(alphabet_lower.index(char)) - - res_indx=[] - for char in indx_lst: - if type(char) == int: - if int(char) <= 2: - res_indx.append(26 + (int(char) - 3)) - else: - res_indx.append(int(char) - 3) - else: - res_indx+=char - - - res_str = "" - count = 0 - for char in res_indx: - if type(char) != int: - res_str += char - else: - if info[count] == 0: - res_str += str(alphabet_lower[int(char)]) - elif info[count] == 1: - res_str += str(alphabet_upper[int(char)]) - count+=1 - - print(res_str) - -if __name__ == "__main__": - import doctest - doctest.testmod() \ No newline at end of file From bc8388c9d61f9d495fef5352fdb63b41cae1377b Mon Sep 17 00:00:00 2001 From: Margaret <62753112+meg-1@users.noreply.github.com> Date: Sat, 29 Jan 2022 14:56:33 +0200 Subject: [PATCH 18/22] Welford average algorithm --- maths/average_welford.py | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 maths/average_welford.py diff --git a/maths/average_welford.py b/maths/average_welford.py new file mode 100644 index 000000000000..2fe94116d9a4 --- /dev/null +++ b/maths/average_welford.py @@ -0,0 +1,21 @@ +def average_welford(values): + """ + >>> average_welford([1, 2, 3, 4, 5]) + 3.0 + >>> average_welford([1.2329435, 2.209462409, 3.230925, 4.47626462, 5.2938759204]) + 3.2886942898799996 + >>> average_welford([-57386462.2329435, 2246262.209462409, 4632463.230925, 856737354.47626462, -243664265.2938759204]) + 112513070.4779665 + """ + avg = 0.0 + """while looping through the list, + we calculate the average of the + current element and the average + of the elements before it""" + for index in range(0, len(values)): + avg += (values[index]-avg)/(index+1) + return avg + +if __name__ == "__main__": + import doctest + doctest.testmod() \ No newline at end of file From 9be479e9ac273131d47da5602f83cfb8e41babc3 Mon Sep 17 00:00:00 2001 From: Margaret <62753112+meg-1@users.noreply.github.com> Date: Wed, 9 Feb 2022 17:31:38 +0200 Subject: [PATCH 19/22] added average welford algorithm --- maths/average_welford.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/maths/average_welford.py b/maths/average_welford.py index 2fe94116d9a4..2aafb18ab936 100644 --- a/maths/average_welford.py +++ b/maths/average_welford.py @@ -1,4 +1,4 @@ -def average_welford(values): +def average_welford(values: list) -> float: """ >>> average_welford([1, 2, 3, 4, 5]) 3.0 From f3fb7e64e046b38f6e5df70da007620115195b53 Mon Sep 17 00:00:00 2001 From: Margaret <62753112+meg-1@users.noreply.github.com> Date: Sat, 19 Mar 2022 14:56:43 +0200 Subject: [PATCH 20/22] is_narcissistic added --- maths/is_narcissistic.py | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) create mode 100644 maths/is_narcissistic.py diff --git a/maths/is_narcissistic.py b/maths/is_narcissistic.py new file mode 100644 index 000000000000..047a1cc41937 --- /dev/null +++ b/maths/is_narcissistic.py @@ -0,0 +1,24 @@ +def is_narcissistic(i: int) -> bool: + + """ + >>> is_narcissistic(1527) + False + >>> is_narcissistic(-1527) + False + >>> is_narcissistic(153) + True + >>> is_narcissistic("153") + True + """ + + """In number theory, a narcissistic number is a number that is + the sum of its own digits each raised to the power of the number of digits. + this alogrithm finds out if given number 'i' is narcissistic or not""" + + i = abs(int(i)) + return sum([int(char)**len(str(i)) for char in str(i)]) == i + + +if __name__ == "__main__": + import doctest + doctest.testmod() \ No newline at end of file From d00d1356838fdd0cb0857f0b42066c197e279610 Mon Sep 17 00:00:00 2001 From: Margaret <62753112+meg-1@users.noreply.github.com> Date: Wed, 23 Mar 2022 17:43:11 +0200 Subject: [PATCH 21/22] added a descriptive name --- maths/is_narcissistic.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/maths/is_narcissistic.py b/maths/is_narcissistic.py index 047a1cc41937..490c344e4b19 100644 --- a/maths/is_narcissistic.py +++ b/maths/is_narcissistic.py @@ -1,4 +1,4 @@ -def is_narcissistic(i: int) -> bool: +def is_narcissistic(num: int) -> bool: """ >>> is_narcissistic(1527) @@ -13,10 +13,10 @@ def is_narcissistic(i: int) -> bool: """In number theory, a narcissistic number is a number that is the sum of its own digits each raised to the power of the number of digits. - this alogrithm finds out if given number 'i' is narcissistic or not""" + this alogrithm finds out if given number 'num' is narcissistic or not""" - i = abs(int(i)) - return sum([int(char)**len(str(i)) for char in str(i)]) == i + num = abs(int(num)) + return sum([int(char)**len(str(num)) for char in str(num)]) == num if __name__ == "__main__": From b3b3cfa83cda21604c9a2f4d978d110666901692 Mon Sep 17 00:00:00 2001 From: Margaret <62753112+meg-1@users.noreply.github.com> Date: Wed, 23 Mar 2022 17:46:44 +0200 Subject: [PATCH 22/22] added max_sectors algorithm --- maths/max_sectors.py | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 maths/max_sectors.py diff --git a/maths/max_sectors.py b/maths/max_sectors.py new file mode 100644 index 000000000000..17fb0256096e --- /dev/null +++ b/maths/max_sectors.py @@ -0,0 +1,19 @@ +def max_sectors(num_cuts: float) -> float: + """ + >>> max_sectors(54) + 1486.0 + >>> max_sectors(7) + 29.0 + >>> max_sectors(22.5) + 265.375 + >>> max_sectors(-222) + -1 + """ + + """here we use a formula to figure out what is the maximum + amount of sectors a circle can be divided by if cut 'num_cuts' times""" + return ((num_cuts+2+num_cuts**2)*(1/2)) if num_cuts >= 0 else -1 + + if __name__ == "__main__": + import doctest + doctest.testmod() \ No newline at end of file