Last active
June 17, 2018 16:44
-
-
Save lucaswhitman/c4eed09c5a9ecfad93e5e5f14d436cc9 to your computer and use it in GitHub Desktop.
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
import re | |
import string | |
def find_first_vowel(word): | |
pattern = re.compile('[a,e,i,o,u]') | |
return pattern.search(word) | |
# removes punctuation and lowers | |
def clean_word(word): | |
exclude = set(string.punctuation) | |
return ''.join(ch for ch in word if ch not in exclude).lower() | |
def translate(word): | |
word = clean_word(word) | |
tail = 'ay' | |
first_vowel = find_first_vowel(word) | |
if not first_vowel: | |
return word + tail | |
first_vowel = first_vowel.group() | |
if word.find(first_vowel) == 0: | |
return word + 'w' + tail | |
first, second = word.split(first_vowel, 1) | |
return first_vowel + second + first + tail | |
def main(): | |
sentence = input('Please enter text and press ENTER: ') | |
sentence = sentence.split() | |
for word in range(len(sentence)): | |
sentence[word] = translate(sentence[word]) | |
return ' '.join(sentence) | |
if __name__ == "__main__": | |
x = main() | |
print(x) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment