Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # 6.189 Homework 2.9 - Pig Latin Funtion
- # 6.189 Homework 2, OPT.1 - Pig Latin Sentences
- def pig_latin(word):
- """Converts a word into Pig Latin and returns it.
- This would be so much cleaner with a Regular Expression!"""
- first_letter = word[0].lower()
- two_let = ''
- punctuation=''
- if word[-1]=="!" or word[-1]=="." or word[-1]=="," or word[-1]=='"' or word[-1]=="'" or word[-1]=="?":
- punctuation=word[-1]
- word=word[:-1]
- if first_letter == 'a' or first_letter == 'e' or first_letter == 'i' or first_letter == 'o' or first_letter == 'u':
- return word+"hay"+punctuation
- else:
- try:
- two_let=word[0:2].lower()
- except:
- two_let=''
- if two_let=='th' or two_let=='st' or two_let=='qu' or two_let=='pl' or two_let=='tr':
- return word[2:]+first_letter+word[1]+'ay'+punctuation
- else:
- return word[1:]+first_letter+'ay'+punctuation
- line_in = input('What do you wish to Pig? ')
- line_out = ''
- for word in line_in.split():
- line_out = line_out + ' ' + pig_latin(word)
- print(line_out)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement