Skip to content

Instantly share code, notes, and snippets.

@NamrataSitlani
Created September 13, 2020 14:27
Show Gist options
  • Save NamrataSitlani/44ad3e01e9008a712ea2b1d68cf86fb4 to your computer and use it in GitHub Desktop.
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
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