Created
July 31, 2016 16:55
-
-
Save nathantowell/f71d8592b469eb1963b16eccd1db36b5 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 | |
suffix = "ay" | |
def translate_word(word): | |
word = re.sub("[^a-zA-Z]+", "", word) | |
new_word = word[1:] + word[0] + suffix | |
if word[0] == word[0].upper(): | |
if word[1:] == word[1:].lower(): | |
return new_word[0].upper() + new_word[1:] | |
elif word[1:] == word[1:].upper(): | |
return new_word.upper() | |
return new_word | |
print("Translate a sentance into pig latin.") | |
input = input("Enter a sentence: ") | |
words = input.split(" ") | |
new_sentence = "" | |
for word in words: | |
new_sentence += translate_word(word) + " " | |
print("Result: " + new_sentence) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment