Question: code in python 3 T! Insert heading comments here.'' def open_file(): ''Insert docstring here.'' pass # insert your code here def get_us_value(fp): ''Insert docstring
\
code in python 3





T! Insert heading comments here.'' def open_file(): "''Insert docstring here.'' pass # insert your code here def get_us_value(fp): "''Insert docstring here.'' pass # insert your code here def get_min_value_and_state(fp): "''Insert docstring here.'' pass # insert your code here def get_max_value_and_state(fp): "''Insert docstring here.''' pass # insert your code here def display_herd_immunity(fp): ""'Insert docstring here.''' pass # insert your code here def write_herd_immunity(fp): "''Insert docstring here.'' pass # insert your code here def main(): "''Insert docstring here.'' pass # insert your code here if == "_main__": name main() 1. open_file() fp : This function takes no parameters, and then uses the try-except format to prompt for a filename, open the data file and return the file pointer if successful. Your function should be able to catch the error and print the error message if it fails to open; and then reprompt. It will reprompt until successful. 2. get_us_value (fp) float: This function takes as an input, fp: the file pointer for the data file. The value for the overall United States MMR coverage is in the line with the label United States. Find and return that value. Read the file line-by-line, use slicing to extract the state and value, keep reading until you find United States. (Use fp.seek (0) to rewind the file to the beginning as your first line of the function. Use a pair of fp.readline (). statements to skip the title and header lines.) This function does not print anything. a. Parameter: file pointer b. Returns: float 3. get_min_value_and_state (fp) string, float: This function takes as an input, fp: the file pointer for the data file. This function should return the minimum value in the file and the associated state. Read the file line-by-line, use slicing to extract the state and value. The algorithm for finding a minimal value is the begin with some large value, let's name it min_value (since these are percentages any value over 100 will work). You will need a second variable, let's name it min_state to record the associated state name. Examine the value in each line, if you find a value that is smaller than min value , you have found a better minimal value. Remember to update the min_state. If you do that with every line, you will have found the minimal value after reading all lines. Return the minimal value and the associated state. Your program should ignore the lines where the values are "NA" (Use fp.seek (0) to rewind the file to the beginning as your first line of the function. Use a pair of fp.readline () statements to skip the title and header lines. There is only one minimal value so we do not have to consider ties.) This function does not print anything. a. Parameter: file pointer b. Returns two values: string, float et_max_value_and_state (fp) string, float: This function takes as an input, fp: the file pointer for the data file. This function should return the maximum value in the file and the associated state. It is similar to the get min value and state function. There is only one maximal value so we do not need to consider ties. This function does not print anything. Your program should ignore the lines where the values are "NA". a. Parameter: file pointer b. Returns two values: string, float state: string, left justified with a field width of 25 value: float, right justified with a field width of 5 and 1 decimal digit of precision Your program should ignore the lines where the values are "NA". a. Parameter: file pointer b. Returns: nothing 6. write_herd_immunity (fp) None: This function writes into a file named herd.txt all the states whose coverage is less than 90%, the minimal value needed for measles herd immunity. Specifications are exactly the same as the previous function display herd immunity, the difference is that instead of displaying on the screen you will be writing to a file. Remember to close the file after writing to it. a. Parameter: file pointer b. Returns: nothing 7. main() None: In main () begin by calling open_file() to get the file pointer. Then read the header line and display it. Finally, call the other functions to extract, calculate and print values. We provide a strings.txt file so you can get the strings and formatting to match the tests. T! Insert heading comments here.'' def open_file(): "''Insert docstring here.'' pass # insert your code here def get_us_value(fp): "''Insert docstring here.'' pass # insert your code here def get_min_value_and_state(fp): "''Insert docstring here.'' pass # insert your code here def get_max_value_and_state(fp): "''Insert docstring here.''' pass # insert your code here def display_herd_immunity(fp): ""'Insert docstring here.''' pass # insert your code here def write_herd_immunity(fp): "''Insert docstring here.'' pass # insert your code here def main(): "''Insert docstring here.'' pass # insert your code here if == "_main__": name main() 1. open_file() fp : This function takes no parameters, and then uses the try-except format to prompt for a filename, open the data file and return the file pointer if successful. Your function should be able to catch the error and print the error message if it fails to open; and then reprompt. It will reprompt until successful. 2. get_us_value (fp) float: This function takes as an input, fp: the file pointer for the data file. The value for the overall United States MMR coverage is in the line with the label United States. Find and return that value. Read the file line-by-line, use slicing to extract the state and value, keep reading until you find United States. (Use fp.seek (0) to rewind the file to the beginning as your first line of the function. Use a pair of fp.readline (). statements to skip the title and header lines.) This function does not print anything. a. Parameter: file pointer b. Returns: float 3. get_min_value_and_state (fp) string, float: This function takes as an input, fp: the file pointer for the data file. This function should return the minimum value in the file and the associated state. Read the file line-by-line, use slicing to extract the state and value. The algorithm for finding a minimal value is the begin with some large value, let's name it min_value (since these are percentages any value over 100 will work). You will need a second variable, let's name it min_state to record the associated state name. Examine the value in each line, if you find a value that is smaller than min value , you have found a better minimal value. Remember to update the min_state. If you do that with every line, you will have found the minimal value after reading all lines. Return the minimal value and the associated state. Your program should ignore the lines where the values are "NA" (Use fp.seek (0) to rewind the file to the beginning as your first line of the function. Use a pair of fp.readline () statements to skip the title and header lines. There is only one minimal value so we do not have to consider ties.) This function does not print anything. a. Parameter: file pointer b. Returns two values: string, float et_max_value_and_state (fp) string, float: This function takes as an input, fp: the file pointer for the data file. This function should return the maximum value in the file and the associated state. It is similar to the get min value and state function. There is only one maximal value so we do not need to consider ties. This function does not print anything. Your program should ignore the lines where the values are "NA". a. Parameter: file pointer b. Returns two values: string, float state: string, left justified with a field width of 25 value: float, right justified with a field width of 5 and 1 decimal digit of precision Your program should ignore the lines where the values are "NA". a. Parameter: file pointer b. Returns: nothing 6. write_herd_immunity (fp) None: This function writes into a file named herd.txt all the states whose coverage is less than 90%, the minimal value needed for measles herd immunity. Specifications are exactly the same as the previous function display herd immunity, the difference is that instead of displaying on the screen you will be writing to a file. Remember to close the file after writing to it. a. Parameter: file pointer b. Returns: nothing 7. main() None: In main () begin by calling open_file() to get the file pointer. Then read the header line and display it. Finally, call the other functions to extract, calculate and print values. We provide a strings.txt file so you can get the strings and formatting to match the tests
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
