Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def translate(phrase):
- r = ""
- while len(phrase)>0:
- if phrase.find(" ")!= -1:
- firstWord = phrase[:phrase.find(" ")]
- #cuts off the firstWord
- phrase = phrase[phrase.find(" ")+1:]
- r += pigLatinWord(firstWord) + " "
- else:
- r += pigLatinWord(phrase)
- phrase = ""
- return r
- def isVowel(char):
- return char in "AEIOUaeiou"
- def isConsonant(char):
- return not isVowel(char)
- def isPunc(char):
- return not str.isalpha(char)
- def iscaseY(char):
- return (char.find('y') != -1 or char.find('Y') != -1)
- def isHyphen(char): # is there a hypen in the word?
- return (char.find('-') != -1 )
- def isQu(char): # is 'qu' or 'Qu' the first 2 letters?
- return char == "qu" or char == "Qu"
- def hypenchar(word): #seperates the words into two words
- first = word[:word.find('-')]
- second = word[word.find('-')+1:]
- return pigLatinWord(first) + "-" + pigLatinWord(second) #pigLatins with '-'
- def yvowel(word):
- addToEnd=""
- front=""
- while word[0]!= "y" and word[0] != "Y"and not isVowel(word[0]):
- addToEnd+= word[0]
- word= word[1:]
- return word+addToEnd+ "ay"
- def pigLatinWord(word):
- r = ""
- addToEnd = ""
- addToStart = ""
- if isPunc(word[0]):
- p = 0
- while p<len(word) and isPunc(word[p]):
- p+=1
- addToStart = word[:p]
- word = word[p:]
- #print "addToStart:", addToStart
- #print "word:", word
- #if iscaseY(word) and len(word) > 2:
- #return yvowel(word)
- #if iscaseY(word) and len(word) ==2:
- #return word[-1] + word[0] + "ay"
- if isPunc(word[-1]):
- j = len(word)-1
- while j>=0 and isPunc(word[j]):
- j-=1
- addToEnd = word[j+1:]
- word = word[:j+1]
- #print "addToEnd:", addToEnd
- #print "word:", word
- if isHyphen(word): #if there is a hyphen...
- r = hypenchar(word) #...do the hyphen related function
- #print "testword:", word
- if isVowel(word[0]):
- r = word + "yay"
- else: #isConsonant
- i = 0
- while i<len(word) and isConsonant(word[i]):
- i+=1
- if isQu(word[:2]): #if 'qu' or 'Qu' is the prefix...
- i = 2 #... make first 2 letters move in following function
- r = word[i:]+word[:i]+"ay"
- if word[0].isupper():
- r = r.capitalize()
- return addToStart + r + addToEnd
- print pigLatinWord("my")
- print pigLatinWord("fly")
- print "-------Word-------"
- print "[Original]:", "Strong"
- print "[Pig Latin]:", pigLatinWord("Strong")
- print "[Original]:", "Oil"
- print "[Pig Latin]:", pigLatinWord("Oil")
- print "[Original]:", "Butter-fly"
- print "[Pig Latin]:", pigLatinWord("Butter-fly")
- print "[Original]:", "Stray"
- print "[Pig Latin]:", pigLatinWord("Stray")
- print "[Original]:", "Yelled"
- print "[Pig Latin]:", pigLatinWord("Yelled")
- print "------Sentence-------"
- print "[Original]:", "\"A green salad,\" said Arthur emphatically."
- print "[Pig Latin]:", translate("\"A green salad,\" said Arthur emphatically.")
- print "[Original]:", "He yelled: \"What?\""
- print "[Pig Latin]:", translate("He yelled: \"What?\"")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement