Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Problem 1: Ocean temperature (ocean_temp.txt or ocean_temp.csv)based on List and Files Problem Specification: 1. Write a function initList (in File) that takes a file object
Problem 1: Ocean temperature (ocean_temp.txt or ocean_temp.csv)based on List and Files Problem Specification: 1. Write a function initList (in File) that takes a file object as parameter and returns a list of values that are read in from the file. 2. Write a function getSize (aList) that takes a list of values as parameter and returns the value count (i.e. how many numbers in the list). 3. Write a function getHighest( aList) that takes a list of values as parameter and returns the highest value of the list. You cannot use predefined max function. 4. Write a function getLowest (aList) that is similar to the getHighest function but returns the lowest temperature. You may use predefined min function. 5. Write a function getAverage(aList) that is similar to the above two functions but returns the average temperature. 6. Write a main function that does the following: a. Prompt the user to enter a filename, open the file to read. If file doesn't exist, ask the user to re-enter (recommend that your program allow up to three tries, however, no point deduction if your program exits on file not found error.) b. Now, call the initList function to get a list of temperature data. c. Call the getSize function to get the number count and print out the number count. d. Call the get Highest function to return the highest temperature of the list. Print it out. e. Call the get Lowest function to return the lowest temperature of the list. Print it out. f. Call the getAverage function to return the average temperature of the list. Print it out. g. Call the main function to execute your program. Problem 2: Average of Numbers and Exception Handling Assume a file containing a series of integer named numbers.txt and exists on the computer's disk. Write a program that calculate the average of all the numbers stored in the file. Modify your program that you wrote so that it can handle the following exception: 1. It should handle any IOError exceptions that are raised when the file is opened, land data is read from it. 2. It should handle any ValueError exceptions that are raised when the items that are read from the file are converted to a number. Problem 1: Ocean temperature (ocean_temp.txt or ocean_temp.csv)based on List and Files Problem Specification: 1. Write a function initList (in File) that takes a file object as parameter and returns a list of values that are read in from the file. 2. Write a function getSize (aList) that takes a list of values as parameter and returns the value count (i.e. how many numbers in the list). 3. Write a function getHighest( aList) that takes a list of values as parameter and returns the highest value of the list. You cannot use predefined max function. 4. Write a function getLowest (aList) that is similar to the getHighest function but returns the lowest temperature. You may use predefined min function. 5. Write a function getAverage(aList) that is similar to the above two functions but returns the average temperature. 6. Write a main function that does the following: a. Prompt the user to enter a filename, open the file to read. If file doesn't exist, ask the user to re-enter (recommend that your program allow up to three tries, however, no point deduction if your program exits on file not found error.) b. Now, call the initList function to get a list of temperature data. c. Call the getSize function to get the number count and print out the number count. d. Call the get Highest function to return the highest temperature of the list. Print it out. e. Call the get Lowest function to return the lowest temperature of the list. Print it out. f. Call the getAverage function to return the average temperature of the list. Print it out. g. Call the main function to execute your program. Problem 2: Average of Numbers and Exception Handling Assume a file containing a series of integer named numbers.txt and exists on the computer's disk. Write a program that calculate the average of all the numbers stored in the file. Modify your program that you wrote so that it can handle the following exception: 1. It should handle any IOError exceptions that are raised when the file is opened, land data is read from it. 2. It should handle any ValueError exceptions that are raised when the items that are read from the file are converted to a number
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started