I am new to Python and need to make a Pig Latin translator, that reads a .txt file, and outputs a new piglatin .txt file for a project. But I cannot figure out how to move the consonant clusters to the end of the word. How would I make it so that I can move the consonant clusters to the right position?
def main():
vowels = ['a', 'e', 'i', 'o', 'u', 'y']
# pigFile = open('C:\Users\grink\OneDrive\Desktop\project\origin.txt', 'r')
pigFile = open('origin.txt', 'r')
pigOut = open('piglatin.txt', 'w')
for line in pigFile.readlines():
pigList = line.split()
t = translate(pigList, vowels)
print("Input: ", pigList)
print("Converted: ", t)
# w = write(t, pigOut)'
writeplatin(t, pigOut)
pigFile.close()
def translate(pigList, vowels):
newPigList = []
for word in pigList:
if word[0] in vowels: # if the word starts with vowel
newPigList.append(word + "way ") #add to new list
else: #if not vowel
newPigList.append(word[1:] + word[0] + "ay")
return newPigList
def writeplatin(pigList, pigOut):
# pigOut.write("n".join(pigList))
for word in pigList:
pigOut.write(word + 'n')
main()
Sorry if this has been answered before, but I’ve been googling for days and haven’t found a solution.
New contributor
Mehemynx is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.