I created a program awhile back to translate a phrase into pig latin. Pretty simple program, but now I am trying to figure out how to get it to read from a file and process it that way. Here is my old program;
def main():
enter = raw_input("Enter a phrase to translate: ")
print enter, "==>", change(enter)
def vowel(text):
for i in range(len(text)):
if test(text[i]) == True:
return i
def trans(word):
#Translates the individual words
x = vowel(word)
if x == None:
output = (word + "yay")
elif x == 0:
output = (word + "yay")
elif x >= 1:
output = (word[x:] + word[:x] + "ay")
else:
pass
return output
def change(phrase):
#allows the program to translate the entire phrase
y = phrase.split()
t = str()
for word in range(len(y)):
t = (t + trans(y[word]) + " ")
return t
def test(char):
#Will test if the first letter is a vowel
vowels="AaEeIiOoUu"
for check in vowels:
if char == check:
return True
return False
main()
I need to take that and get it to read from a txt file that contains the following:
roses are red
violets are blue
etc.
Seems like a pretty simple solution I just can't seem to figure out how to get it to work.