Ancay youyay eakspay igpay atinlay? (Can you speak pig latin?) If you can’t, here are the rules: If a word begins with a consonant, take all of the letters before the first vowel and move them to the end of the word, then add ay to the end of the word. Examples: pig → igpay, there → erethay. If a word begins with a vowel (a, e, i, o, u, or y), simply add yay to the end of the word. For this problem, y is always a vowel. Examples: and → andyay, ordinary → ordinaryyay. Although there are many variants of Pig Latin (such as Kedelkloppersprook in Germany), for this problem we will always use the rules described above. A friend of yours was frustrated with everyone writing in Pig Latin and has asked you to write a program to translate to Pig Latin for him. Ouldway youyay ebay osay indkay otay oday ityay? (Would you be so kind to do it?) Inputs consist of lines of text that you will individually translate from a text file given by the user. If the file cannot be opened for some reason, output "Unable to open input file." and quit. Do not prompt the user to enter an input file name. There is no limit to the number of lines, however you must input all lines before translating. No punctuation or special characters will appear in the input. Output each line given to you translated back to the user. Needs to include "def translate(word):" for returning the word based on the pig latin rules, "def read_input(file_name):" to return a list of lines read from the file, "def parse_line(line):" to take the line given by the parameter line and split it into a list of words, running each word through the translate function and returning it as a
Max Function
Statistical function is of many categories. One of them is a MAX function. The MAX function returns the largest value from the list of arguments passed to it. MAX function always ignores the empty cells when performing the calculation.
Power Function
A power function is a type of single-term function. Its definition states that it is a variable containing a base value raised to a constant value acting as an exponent. This variable may also have a coefficient. For instance, the area of a circle can be given as:
Ancay youyay eakspay igpay atinlay? (Can you speak pig latin?) If you can’t, here are the rules:
If a word begins with a consonant, take all of the letters before the first vowel and move them to the end of the word, then add ay to the end of the word. Examples: pig → igpay, there → erethay.
If a word begins with a vowel (a, e, i, o, u, or y), simply add yay to the end of the word. For this problem, y is always a vowel. Examples: and → andyay, ordinary → ordinaryyay.
Although there are many variants of Pig Latin (such as Kedelkloppersprook in Germany), for this problem we will always use the rules described above.
A friend of yours was frustrated with everyone writing in Pig Latin and has asked you to write a program to translate to Pig Latin for him. Ouldway youyay ebay osay indkay otay oday ityay? (Would you be so kind to do it?)
Inputs consist of lines of text that you will individually translate from a text file given by the user. If the file cannot be opened for some reason, output "Unable to open input file." and quit.
Do not prompt the user to enter an input file name.
There is no limit to the number of lines, however you must input all lines before translating. No punctuation or special characters will appear in the input.
Output each line given to you translated back to the user.
Needs to include "def translate(word):" for returning the word based on the pig latin rules, "def read_input(file_name):" to return a list of lines read from the file, "def parse_line(line):" to take the line given by the parameter line and split it into a list of words, running each word through the translate function and returning it as a translated string, "def parse_all_lines(lines):" that returns a new list of lines where each line is translated and running each line through the parse_line function.
Finally, it is tested with
"if __name__ == "__main__":
file_name = input()
lines = read_input(file_name)
if len(lines) == 0:
print("Unable to open input file.")
else:
for line in parse_all_lines(lines):
print(line)"
Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 2 images