Skip to content

Instantly share code, notes, and snippets.

@cowdinosaur
Last active October 18, 2021 01:54
Show Gist options
  • Save cowdinosaur/51bc87cc0d8527aaf6dbf2569f86a466 to your computer and use it in GitHub Desktop.
Save cowdinosaur/51bc87cc0d8527aaf6dbf2569f86a466 to your computer and use it in GitHub Desktop.
pig latin
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