From 243b4d4bf73361b6577388a5d7a6a07145c88593 Mon Sep 17 00:00:00 2001 From: Rohan Sardar <77870108+RohanSardar@users.noreply.github.com> Date: Wed, 4 Oct 2023 21:20:32 +0530 Subject: [PATCH 01/11] Program to convert a given string to Pig Latin This is a program to convert a user given string to its respective Pig Latin form As per wikipedia (link: https://en.wikipedia.org/wiki/Pig_Latin#Rules) For words that begin with consonant sounds, all letters before the initial vowel are placed at the end of the word sequence. Then, "ay" is added, as in the following examples: "pig" = "igpay" "latin" = "atinlay" "banana" = "ananabay" When words begin with consonant clusters (multiple consonants that form one sound), the whole sound is added to the end when speaking or writing. "friends" = "iendsfray" "smile" = "ilesmay" "string" = "ingstray" For words that begin with vowel sounds, one just adds "hay", "way" or "yay" to the end. Examples are: "eat" = "eatway" "omelet" = "omeletway" "are" = "areway" --- strings/pig_latin.py | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 strings/pig_latin.py diff --git a/strings/pig_latin.py b/strings/pig_latin.py new file mode 100644 index 000000000000..c195132c0824 --- /dev/null +++ b/strings/pig_latin.py @@ -0,0 +1,16 @@ +def pig_latin(sentence): + sentence = sentence.lower() + length = len(sentence) + if sentence[0] in "aeiou": + result = sentence + "way" + else: + for i in range(length): + if sentence[i] in "aeiou": + break + result = sentence[i:] + sentence[:i] + "ay" + return result + +statement = input("Enter a string: ") +answer = pig_latin(statement) + +print("The PIG LATIN of the entered string is \"{}\"".format(answer)) From c6e8a138a3841ffd4d4921167e8c34da68e6ca44 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 4 Oct 2023 15:56:47 +0000 Subject: [PATCH 02/11] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- strings/pig_latin.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/strings/pig_latin.py b/strings/pig_latin.py index c195132c0824..251ed7d58999 100644 --- a/strings/pig_latin.py +++ b/strings/pig_latin.py @@ -10,7 +10,8 @@ def pig_latin(sentence): result = sentence[i:] + sentence[:i] + "ay" return result + statement = input("Enter a string: ") answer = pig_latin(statement) -print("The PIG LATIN of the entered string is \"{}\"".format(answer)) +print('The PIG LATIN of the entered string is "{}"'.format(answer)) From cf1830c2013485ed5d61d34e944a88f1d3cc79e3 Mon Sep 17 00:00:00 2001 From: Rohan Sardar <77870108+RohanSardar@users.noreply.github.com> Date: Wed, 4 Oct 2023 22:16:54 +0530 Subject: [PATCH 03/11] Update pig_latin.py Added f-string --- strings/pig_latin.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/strings/pig_latin.py b/strings/pig_latin.py index 251ed7d58999..58e00afa34c9 100644 --- a/strings/pig_latin.py +++ b/strings/pig_latin.py @@ -14,4 +14,4 @@ def pig_latin(sentence): statement = input("Enter a string: ") answer = pig_latin(statement) -print('The PIG LATIN of the entered string is "{}"'.format(answer)) +print(f"The PIG LATIN of the entered string is \"{answer}\"") From 5cebe8f8cad0ae81c18b0d9bdbf0c2a341bc450a Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 4 Oct 2023 16:47:31 +0000 Subject: [PATCH 04/11] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- strings/pig_latin.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/strings/pig_latin.py b/strings/pig_latin.py index 58e00afa34c9..9568a926d187 100644 --- a/strings/pig_latin.py +++ b/strings/pig_latin.py @@ -14,4 +14,4 @@ def pig_latin(sentence): statement = input("Enter a string: ") answer = pig_latin(statement) -print(f"The PIG LATIN of the entered string is \"{answer}\"") +print(f'The PIG LATIN of the entered string is "{answer}"') From 76b3f7e14675adf6959f420e58f910ec2188c031 Mon Sep 17 00:00:00 2001 From: Rohan Sardar <77870108+RohanSardar@users.noreply.github.com> Date: Thu, 5 Oct 2023 08:20:56 +0530 Subject: [PATCH 05/11] Update pig_latin.py --- strings/pig_latin.py | 32 +++++++++++++++++++++++++++++--- 1 file changed, 29 insertions(+), 3 deletions(-) diff --git a/strings/pig_latin.py b/strings/pig_latin.py index 9568a926d187..8dde5ebbf51f 100644 --- a/strings/pig_latin.py +++ b/strings/pig_latin.py @@ -1,4 +1,31 @@ -def pig_latin(sentence): +# pig_latin.py + +def pig_latin(sentence:str) -> str: + + """Compute the piglatin of a given string. + + Usage examples: + >>> pig_latin("pig") + 'igpay' + >>> pig_latin("latin") + 'atinlay' + >>> pig_latin("banana") + 'ananabay' + >>> pig_latin("friends") + 'iendsfray' + >>> pig_latin("smile") + 'ilesmay' + >>> pig_latin("string") + 'ingstray' + >>> pig_latin("eat") + 'eatway' + >>> pig_latin("omelet") + 'omeletway' + >>> pig_latin("are") + 'areway' + + """ + sentence = sentence.lower() length = len(sentence) if sentence[0] in "aeiou": @@ -10,8 +37,7 @@ def pig_latin(sentence): result = sentence[i:] + sentence[:i] + "ay" return result - statement = input("Enter a string: ") answer = pig_latin(statement) -print(f'The PIG LATIN of the entered string is "{answer}"') +print(f"The PIG LATIN of the entered string is \"{answer}\"") From 561958e573b6ea5a9d9573921e6d95f96347a18e Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 5 Oct 2023 02:51:25 +0000 Subject: [PATCH 06/11] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- strings/pig_latin.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/strings/pig_latin.py b/strings/pig_latin.py index 8dde5ebbf51f..16bdbf071d84 100644 --- a/strings/pig_latin.py +++ b/strings/pig_latin.py @@ -1,7 +1,7 @@ # pig_latin.py -def pig_latin(sentence:str) -> str: +def pig_latin(sentence: str) -> str: """Compute the piglatin of a given string. Usage examples: @@ -37,7 +37,8 @@ def pig_latin(sentence:str) -> str: result = sentence[i:] + sentence[:i] + "ay" return result + statement = input("Enter a string: ") answer = pig_latin(statement) -print(f"The PIG LATIN of the entered string is \"{answer}\"") +print(f'The PIG LATIN of the entered string is "{answer}"') From 9c6657c95a5cbfcf4f677f9fe118c6fd8c036995 Mon Sep 17 00:00:00 2001 From: Rohan Sardar <77870108+RohanSardar@users.noreply.github.com> Date: Thu, 5 Oct 2023 08:34:24 +0530 Subject: [PATCH 07/11] Update pig_latin.py --- strings/pig_latin.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/strings/pig_latin.py b/strings/pig_latin.py index 16bdbf071d84..b714e049edef 100644 --- a/strings/pig_latin.py +++ b/strings/pig_latin.py @@ -1,7 +1,7 @@ # pig_latin.py +def pig_latin(sentence:str) -> str: -def pig_latin(sentence: str) -> str: """Compute the piglatin of a given string. Usage examples: @@ -37,8 +37,8 @@ def pig_latin(sentence: str) -> str: result = sentence[i:] + sentence[:i] + "ay" return result - -statement = input("Enter a string: ") +#statement = input("Enter a string: ") +statement = "friends" #giving a sample input answer = pig_latin(statement) -print(f'The PIG LATIN of the entered string is "{answer}"') +print(f"The PIG LATIN of the given string is \"{answer}\"") From 3034202d4b389326c742dd1874865696274ca635 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Thu, 5 Oct 2023 03:05:01 +0000 Subject: [PATCH 08/11] [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci --- strings/pig_latin.py | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/strings/pig_latin.py b/strings/pig_latin.py index b714e049edef..63eea302feda 100644 --- a/strings/pig_latin.py +++ b/strings/pig_latin.py @@ -1,7 +1,7 @@ # pig_latin.py -def pig_latin(sentence:str) -> str: +def pig_latin(sentence: str) -> str: """Compute the piglatin of a given string. Usage examples: @@ -37,8 +37,9 @@ def pig_latin(sentence:str) -> str: result = sentence[i:] + sentence[:i] + "ay" return result -#statement = input("Enter a string: ") -statement = "friends" #giving a sample input + +# statement = input("Enter a string: ") +statement = "friends" # giving a sample input answer = pig_latin(statement) -print(f"The PIG LATIN of the given string is \"{answer}\"") +print(f'The PIG LATIN of the given string is "{answer}"') From 14f7e30407088a0f3816ba614fa6b4ce96c33fc9 Mon Sep 17 00:00:00 2001 From: Christian Clauss Date: Thu, 5 Oct 2023 10:43:12 +0200 Subject: [PATCH 09/11] Update pig_latin.py --- strings/pig_latin.py | 45 ++++++++++++++++++++++---------------------- 1 file changed, 22 insertions(+), 23 deletions(-) diff --git a/strings/pig_latin.py b/strings/pig_latin.py index 63eea302feda..36c5fb7fbf7e 100644 --- a/strings/pig_latin.py +++ b/strings/pig_latin.py @@ -1,9 +1,8 @@ -# pig_latin.py - - -def pig_latin(sentence: str) -> str: +def pig_latin(word: str) -> str: """Compute the piglatin of a given string. + https://en.wikipedia.org/wiki/Pig_Latin + Usage examples: >>> pig_latin("pig") 'igpay' @@ -23,23 +22,23 @@ def pig_latin(sentence: str) -> str: 'omeletway' >>> pig_latin("are") 'areway' - + >>> pig_latin(" ") + '' + >>> pig_latin(None) + '' """ - - sentence = sentence.lower() - length = len(sentence) - if sentence[0] in "aeiou": - result = sentence + "way" - else: - for i in range(length): - if sentence[i] in "aeiou": - break - result = sentence[i:] + sentence[:i] + "ay" - return result - - -# statement = input("Enter a string: ") -statement = "friends" # giving a sample input -answer = pig_latin(statement) - -print(f'The PIG LATIN of the given string is "{answer}"') + if not (word or "").strip(): + return "" + word = word.lower() + if word[0] in "aeiou": + return f"{word}way" + for i, char in enumerate(word): + if char in "aeiou": + break + return f"{word[i:]}{word[:i]}ay" + + +if __name__ == "__main__": + print(f"{pig_latin("friends") = }") + word = input("Enter a word: ") + print(f"{pig_latin(word) = }") From 8ca9f1fc47dcc95bddaf801156c111c16c7e6ea8 Mon Sep 17 00:00:00 2001 From: Christian Clauss Date: Thu, 5 Oct 2023 10:44:41 +0200 Subject: [PATCH 10/11] Update pig_latin.py --- strings/pig_latin.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/strings/pig_latin.py b/strings/pig_latin.py index 36c5fb7fbf7e..1dbdc6ad9b25 100644 --- a/strings/pig_latin.py +++ b/strings/pig_latin.py @@ -32,7 +32,7 @@ def pig_latin(word: str) -> str: word = word.lower() if word[0] in "aeiou": return f"{word}way" - for i, char in enumerate(word): + for i, char in enumerate(word): # noqa: B007 if char in "aeiou": break return f"{word[i:]}{word[:i]}ay" From 65f571312116569dc84b98993d4a1d0cb9172812 Mon Sep 17 00:00:00 2001 From: Christian Clauss Date: Thu, 5 Oct 2023 10:48:54 +0200 Subject: [PATCH 11/11] Update pig_latin.py --- strings/pig_latin.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/strings/pig_latin.py b/strings/pig_latin.py index 1dbdc6ad9b25..457dbb5a6cf6 100644 --- a/strings/pig_latin.py +++ b/strings/pig_latin.py @@ -39,6 +39,6 @@ def pig_latin(word: str) -> str: if __name__ == "__main__": - print(f"{pig_latin("friends") = }") + print(f"{pig_latin('friends') = }") word = input("Enter a word: ") print(f"{pig_latin(word) = }")