Menu

[Solved]E None Question 11a 12 Points Write Definition Line Class Named Stote One Line Docstring D Q37218411

e) none of the above Question 11A (12 points) Write a definition line for a class named stote and a one-line docstring that dTIj ias been saved in a file named state.py code that performs the following tasks (each task takes one line): 1. 2. 3. 4 cheQuestion 13 (20 points) Write a function named linestats. The function linestats takes three parameters: inFile, a string thae) none of the above Question 11A (12 points) Write a definition line for a class named stote and a one-line docstring that describes what a State is Write definitions for the following methods (functions) in the code for the class: 1. An initialization method. The initialization method should: Take a string parameter, nane, and assign it as attribute nane of the state being created Create a list variable, universities, for the state being created and initialize it to the empty list A method named add university. This method should take the name of a university as a string parameter and add it to the list of universities for that state. Arnethod named is home of. This method should take the naneof a university as a string parameter. If the university is in the state’s list of universities it should return True, otherwise it should return False. 2. 3· Question 11B (8 points) Assume that the code for the class state (Question 11A) has been saved in a file named state.py. Write code that performs the following tasks (each task takes one line): 1. import the module that defines the class State 2. create a state named New 3ersey 3. add universities NJIT and Princeton to New 3ersey 4. check whether New Jersey is home of MIT and print the result Question 12 (20 points) Write a function named wordt inecount with the following input and output DOLL TIj ias been saved in a file named state.py code that performs the following tasks (each task takes one line): 1. 2. 3. 4 check whether New Jersey is home of MIT and print the result import the module that defines the class State create a state named New Jersey add universities NJIT and Princeton to New Jersey Question 12 (20 points) Write a function named wordl inecount with the following input and output: Input: Output: return a dictionary in which each unique word in inFile is a key and the corresponding v a string parameter, inFile, that is the name of a file is the number of lines on which that word occurs The file inFile contains only lower case letters and white space For example, if the file ben. txt contains these lines: tell me and i forget teach me and i remember involve me and i Learn then the following would be correct output >>> print (wordLinecount (‘ben.txt’)) (‘remember 1, and’ 3, ell: 1, me: 3, forget’: 1, learn’: 1, involve’:1, 3, teach’ 1) Et DOLL Question 13 (20 points) Write a function named linestats. The function linestats takes three parameters: inFile, a string that is the name of an input file 2. outFile, a string that is the name of an output file 3. threshold, an int that is the length above which a word is considered significant 1. The function Linestats should read and analyze each line of the input file and write two statistics separated by a space, about the line to a corresponding line of the output file The two statistics for each line are: the number of words the number of distinct significant words (that is, words longer than threshold) 1, 2. Hint: if a word occurs more than once on a line it counts as a single word. Upper and lower case characters are considered the same (‘word’ and ‘word’ are the same word). The input file contains only upper and lower case letters and white space. For example, if the file fish.txt contains the following lines Yes some are red and some are blue Some are old and some are new Then the function call: linestats(‘fish.txt’, fishout.txt, 3) should produce an output file fishout.txt with the following content: 8 2 7 1 DOLL Show transcribed image text e) none of the above Question 11A (12 points) Write a definition line for a class named stote and a one-line docstring that describes what a State is Write definitions for the following methods (functions) in the code for the class: 1. An initialization method. The initialization method should: Take a string parameter, nane, and assign it as attribute nane of the state being created Create a list variable, universities, for the state being created and initialize it to the empty list A method named add university. This method should take the name of a university as a string parameter and add it to the list of universities for that state. Arnethod named is home of. This method should take the naneof a university as a string parameter. If the university is in the state’s list of universities it should return True, otherwise it should return False. 2. 3· Question 11B (8 points) Assume that the code for the class state (Question 11A) has been saved in a file named state.py. Write code that performs the following tasks (each task takes one line): 1. import the module that defines the class State 2. create a state named New 3ersey 3. add universities NJIT and Princeton to New 3ersey 4. check whether New Jersey is home of MIT and print the result Question 12 (20 points) Write a function named wordt inecount with the following input and output DOLL
TIj ias been saved in a file named state.py code that performs the following tasks (each task takes one line): 1. 2. 3. 4 check whether New Jersey is home of MIT and print the result import the module that defines the class State create a state named New Jersey add universities NJIT and Princeton to New Jersey Question 12 (20 points) Write a function named wordl inecount with the following input and output: Input: Output: return a dictionary in which each unique word in inFile is a key and the corresponding v a string parameter, inFile, that is the name of a file is the number of lines on which that word occurs The file inFile contains only lower case letters and white space For example, if the file ben. txt contains these lines: tell me and i forget teach me and i remember involve me and i Learn then the following would be correct output >>> print (wordLinecount (‘ben.txt’)) (‘remember 1, and’ 3, ell: 1, me: 3, forget’: 1, learn’: 1, involve’:1, 3, teach’ 1) Et DOLL
Question 13 (20 points) Write a function named linestats. The function linestats takes three parameters: inFile, a string that is the name of an input file 2. outFile, a string that is the name of an output file 3. threshold, an int that is the length above which a word is considered significant 1. The function Linestats should read and analyze each line of the input file and write two statistics separated by a space, about the line to a corresponding line of the output file The two statistics for each line are: the number of words the number of distinct significant words (that is, words longer than threshold) 1, 2. Hint: if a word occurs more than once on a line it counts as a single word. Upper and lower case characters are considered the same (‘word’ and ‘word’ are the same word). The input file contains only upper and lower case letters and white space. For example, if the file fish.txt contains the following lines Yes some are red and some are blue Some are old and some are new Then the function call: linestats(‘fish.txt’, fishout.txt, 3) should produce an output file fishout.txt with the following content: 8 2 7 1 DOLL

Expert Answer


Answer to e) none of the above Question 11A (12 points) Write a definition line for a class named stote and a one-line docstring t… . . .

OR


Leave a Reply

Your email address will not be published. Required fields are marked *