Skip to content

Instantly share code, notes, and snippets.

@nathantowell
Created July 31, 2016 16:55
Show Gist options
  • Save nathantowell/f71d8592b469eb1963b16eccd1db36b5 to your computer and use it in GitHub Desktop.
Save nathantowell/f71d8592b469eb1963b16eccd1db36b5 to your computer and use it in GitHub Desktop.
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