Skip to content

Instantly share code, notes, and snippets.

@pzp1997
Last active August 29, 2015 14:06
Show Gist options
  • Save pzp1997/35efecf36e4bce6bf4a5 to your computer and use it in GitHub Desktop.
Save pzp1997/35efecf36e4bce6bf4a5 to your computer and use it in GitHub Desktop.
#!/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