Define a function read_data that accepts a single argument corresponding to the filename, and returns a...
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
Define a function read_data that accepts a single argument corresponding to the filename, and returns a list of lists. You can find an example file to work with in the Brightspace and the startercode section of the Vocareum • Each line in the data file in question follows this format: "[Day of the week], num1, num2, num3 ..... . Monday, 965, 126, 330, 432,188, 775, 900, 304,510,899, 98,558, 226,734, 377 Tuesday, 656, 108, 991, 424, 119,541, 211, 564, 101 Wednesday, 647, 347,246, 457, 400, 395, 682,928, 641, 353, 12, 658, 137,358,65 Thursday, 195,258, 173, 851, 121, 43, 692, 673, 298, 232,798,283 *** • The function must return a list of lists where each sublist represents one line from the file. All the numbers must be converted to int datatype in the returned value Sample output: >>print (read_data('sample_data.txt')) [['Monday, 955, 126, 330, 432, 188, 775, 900, 304, 510, 899, 98, 558, 226, 734, 3771, [Tuesday, 656, 108, 991, 424, 119, 541, 211, 664, 1011, ['Wednesday', 647, 347, 246, 457, 400, 396, 682, 928, 643, 353, 12, 658, 137, 358, 651,1 . Task 2: Define a function find_averages that accepts the list of lists from the read_data function and returns a list of special averages computed according to the rules specified below As you iterate through the numbers, you are checking the sum of digits for each number, and when you encounter a number with its sum of digits equal to the number corresponding to the day of the week, you compute the average of all the preceding numbers including the current number The days of the week are numbered starting with 1 for Monday, 2 for Tuesday and so on up to 7 for Sunday For example, consider the line: Thursday, 352, 984, 71, 436, 145, 238, 739, 394, 854, 392, 847, We iterate through each number in the line checking if the sum of digits is equal to 4 (Thursday): 574 352 3+5+2= 10: 1+0 - 11 984: 9+8+421 2+1 3 71: 7+18 436: 4+3+6 13: 1+3 - 4 And when we find such number, we compute the average of all the preceding numbers for that line including the current number: Avg (352 + 984 71+ 436)/4 If no number meets the specified condition, compute the average of all the numbers . Iterate through all the lines in the list to compute averages based on the rules above and return a list of all averages. Round the averages up to 2 decimals. Define a function read_data that accepts a single argument corresponding to the filename, and returns a list of lists. You can find an example file to work with in the Brightspace and the startercode section of the Vocareum • Each line in the data file in question follows this format: "[Day of the week], num1, num2, num3 ..... . Monday, 965, 126, 330, 432,188, 775, 900, 304,510,899, 98,558, 226,734, 377 Tuesday, 656, 108, 991, 424, 119,541, 211, 564, 101 Wednesday, 647, 347,246, 457, 400, 395, 682,928, 641, 353, 12, 658, 137,358,65 Thursday, 195,258, 173, 851, 121, 43, 692, 673, 298, 232,798,283 *** • The function must return a list of lists where each sublist represents one line from the file. All the numbers must be converted to int datatype in the returned value Sample output: >>print (read_data('sample_data.txt')) [['Monday, 955, 126, 330, 432, 188, 775, 900, 304, 510, 899, 98, 558, 226, 734, 3771, [Tuesday, 656, 108, 991, 424, 119, 541, 211, 664, 1011, ['Wednesday', 647, 347, 246, 457, 400, 396, 682, 928, 643, 353, 12, 658, 137, 358, 651,1 . Task 2: Define a function find_averages that accepts the list of lists from the read_data function and returns a list of special averages computed according to the rules specified below As you iterate through the numbers, you are checking the sum of digits for each number, and when you encounter a number with its sum of digits equal to the number corresponding to the day of the week, you compute the average of all the preceding numbers including the current number The days of the week are numbered starting with 1 for Monday, 2 for Tuesday and so on up to 7 for Sunday For example, consider the line: Thursday, 352, 984, 71, 436, 145, 238, 739, 394, 854, 392, 847, We iterate through each number in the line checking if the sum of digits is equal to 4 (Thursday): 574 352 3+5+2= 10: 1+0 - 11 984: 9+8+421 2+1 3 71: 7+18 436: 4+3+6 13: 1+3 - 4 And when we find such number, we compute the average of all the preceding numbers for that line including the current number: Avg (352 + 984 71+ 436)/4 If no number meets the specified condition, compute the average of all the numbers . Iterate through all the lines in the list to compute averages based on the rules above and return a list of all averages. Round the averages up to 2 decimals.
Expert Answer:
Answer rating: 100% (QA)
P ython def readdatafilename datalist with openfilename r as file for line in file line l... View the full answer
Related Book For
Posted Date:
Students also viewed these programming questions
-
What percentage of your gross salary does the Consumer Financial Protection Bureau suggest your student loan payment be in order to be affordable and limit your risk of delinquency and default?
-
Use the attached "words.txt" file to store the words along with their ranks in an AVL tree. Then provide the user the option to search for any word. If the word exists the program displays the rank...
-
The diagonals of a quadrilateral ABCD intersect each other at the point O such that AO/BO=CO/DO. Show that ABCD is a trapezium.
-
Suppose you are a depositor at First Street Bank. You hear a rumor that the bank has suffered serious losses on its loans. Every depositor knows that the rumor isnt true, but each thinks that most...
-
Reconsider the Goferbroke Co. case study when using utilities, as presented in Section 9.9. a. Beginning with the decision tree shown in Figure 9.23 (Available in one of this chapter's Excel files),...
-
A ideal gas having f degrees of freedom is kept inside a thermally insulated vessel, the vessel has two large pistons each with charge of +Q and -Q. Assume charges are uniformly distributed. Pistons...
-
Discuss the following issues relating to criticism of conventional accounting. 1 Conventional accounting uses the accrual convention.What is the accrual convention? What is the main benefit of...
-
Twentieth Century Fox (Fox) owned and distributed the successful motion picture The Commitments. The film tells the story of a group of young Irish men and women who form a soul music band. In the...
-
How do pilots interpret sustainable practices to improve workforce development and diversity, increase quality and efficiency while reducing costs in aviation and aerospace operations.
-
Prepare an estate tax return (Form 706) for Marcia Miller, who died July 23, 2019. Marcia (born April 2, 1930) resided at 117 Brandywine Way, Eastern City, PA 19000 and was a lifelong Pennsylvania...
-
Jayden works for Miami University. He uses his technology and business acumen when interacting with both the business and IT areas to develop strong and sustainable infrastructure. He's really the...
-
A taxpayer needs help identifying and understanding their Adjusted Gross Income ( AGI ) for the tax year of 2 0 2 3 . Filing status: Single Their total income consists of the following: Wages $ 2 0 ,...
-
Kingsport Containers Company makes a single product that is subject to wide seasonal variations in demand. The company uses a job - order costing system and computes plantwide predetermined overhead...
-
For the last few years, you have been running StoreWell, a company supplying refrigerants to storage and logistics clients. Given the market shifts during COVID-19. you decide to divert some of your...
-
Lincolnshire Lumber sells boards for many uses including wood floors. For floors, the boards are sold to local installers or do - it - yourself homeowners. The boards go through up to four processes,...
-
The City of Piglet reported property tax revenues in 2020 in the amount of $10 million. The deferred inflow-property taxes reported in the General Fund's balance sheet was $300,000 on December 31,...
-
Describe what changes you would make in the business to arrive at the measures you proposed, including changes to organization, strategy, and management. Relate your proposal to any current events or...
-
The purpose of this case is to come up with a contingency plan[s] in order to sustain the program Move With Me, a program that serves thousands of community members throughout Lower Manhattan. The...
-
In Example 14.16 we used "$@" to refer to the parameters passed to ll. What would happen if we removed the quote marks? (Try this for files whose names contain spaces!) Read the man page for bash and...
-
Write code for the tree_iter type (struct) andthe ti_create, ti_done, ti_next, ti_val, and ti_delete functions employed in Example 6.73.
-
Perhaps the most common form of run-time instrumentation counts the number of times that each basic block is executed. Since basic blocks are short, adding a load-increment-store instruction sequence...
-
8P1 In Exercises 1722, evaluate the permutation.
-
45P5 In Exercises 1722, evaluate the permutation.
-
Let A and B be events with P (A) = 0.2 and P (B) = 0.9. Assume that A and B are independent. Find P (A and B).
Study smarter with the SolutionInn App