Last active
August 29, 2015 14:06
-
-
Save pzp1997/35efecf36e4bce6bf4a5 to your computer and use it in GitHub Desktop.
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
#!/usr/bin/env python2.7 | |
def pig_latin(message): | |
vowel = ["a", "e", "i", "o", "u"] | |
message = message.lower().split(" ") | |
for word in range(len(message)): | |
if message[word][0] in vowel: | |
message[word] = message[word] + "way" | |
else: | |
i = 1 | |
try: | |
while not message[word][i] in vowel: | |
i += 1 | |
except IndexError: | |
i = 0 | |
message[word] = message[word][i:] + message[word][:i] + "ay" | |
return " ".join(message) | |
def main(): | |
from sys import argv | |
if len(argv) < 2: | |
while True: | |
inpt = raw_input("Pig Latin: ") | |
if inpt.lower() == "exit": | |
raise SystemExit | |
print pig_latin(inpt) | |
print pig_latin(" ".join(argv[1:])) | |
if __name__ == "__main__": | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment