Last active
October 18, 2021 01:54
-
-
Save cowdinosaur/51bc87cc0d8527aaf6dbf2569f86a466 to your computer and use it in GitHub Desktop.
pig latin
This file contains hidden or 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
vowels = 'aeiou' | |
consonants = 'bcdfghjklmnpqrstvwxyz' | |
sentence = "how do you say ... in pig latin?" | |
### YOUR CODE HERE! | |
def translate_word(word): | |
if len(word) >= 2: | |
if word[0] in consonants and word[1] in vowels: | |
word = word[1:] + word[:1] + "ay" | |
elif word[0] in consonants and word[1] in consonants: | |
word = word[2:] + word[:2] + "ay" | |
elif word[0] in vowels: | |
word = word + "way" | |
return word | |
output = [] | |
for a_word in sentence.split(): | |
output.append(translate_word(a_word)) | |
print(" ".join(output)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment