Created
September 13, 2020 14:27
-
-
Save NamrataSitlani/44ad3e01e9008a712ea2b1d68cf86fb4 to your computer and use it in GitHub Desktop.
Write a function that converts a sentence into Pig Latin. https://en.wikipedia.org/wiki/Pig_Latin#Rules
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def pig_latin_sentence(sentence): | |
VOWELS = "aeiou" | |
new_sentence = [] | |
for word in sentence.split(): | |
consonants = 0 | |
if word[0].lower() in VOWELS: | |
new_sentence.append(word + 'yay') | |
continue | |
for letter in word.lower(): | |
if letter not in VOWELS: | |
consonants += 1 | |
continue | |
new_sentence.append(word[consonants:] + word[:consonants] + 'ay') | |
break | |
return " ".join(new_sentence) | |
if __name__ == '__main__': | |
sentence = "smile floor happy egg" | |
print(pig_latin_sentence(sentence)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment