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...
-
How prevalent and important are small entrepreneurial firms in economies around the globe?
-
How do talent management evidence-based HR support Mundy's efforts to offer solutions?
-
What is the formula for the acid-test ratio?
-
Internet giant Zoidle, a U. S. company, generated sales of 2.5 billion in the United Kingdom in 2013 (approximately $ 4 billion in U. S. dollars). Its net profits before taxes on these sales were ...
-
Consider the table shown below to answer the question posed in part a. Parts b and c are independent of the given table. Number of Share (millions) Stock Price = Market Capitalization ($ millions)...
-
Nathan is married with two children and has AGI of $405,000. He also has the following AMT adjustments and preferences: Itemized deductions: medical after floor:$5,375 regular tax taxes: $34,354...
-
Make up the competition in the vape pen industry. As well, as perform a situation analysis on the cannabis disposable pen industry. Provide the strengths and the weaknesses of the business. What are...
-
Evaluate the idea that a world hegemon creates stability in the global system. What are the pros and cons of this theory? If , as some political scientists predict, U . S . hegemony is coming to an...
-
Marigold, Inc. is facing a problem with their 4th quarter absorption costing net operating income on December 25. Their net operating income target is $350,000 and the data so far is as follows: ...
-
1. The beta of ABC's common stock is 1.1, the dividend paid is $3.50, and the stock price is $82.00. The expected market return is 12% and the risk-free rate is 6%. Calculate the cost of equity ? 2....
-
Provide answers to all of the questions below. Define mise en place and explain its purpose in regards to preparing, cooking and presenting food. 2 Briefly describe uses for the following commercial...
-
Production Costs Work in process, beginning of period: Materials$5,200 Labor 4,600 Factory overhead 2,000 $11,800 Costs incurred during month: Materials$20,000 Labor 15,000 Factory overhead 12,000...
-
E F G H A. Foot and total where required the following T-Accounts below for Fred Consulting on March 31, 2023 B. Prepare a trial balance, listing the accounts and their balances in proper order. A B...
-
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...
-
Explain why mass transfer correlations for co-flow cannot be used for countercurrent flow.
-
Why are mass transfer coefficients from clean drops higher than mass transfer coefficients in dirty systems? What is the practical significance of this?
-
How do we determine the height of packing required for a concentrated absorber or stripper if \(\mathrm{H}_{\mathrm{G}}\) is not constant?
Study smarter with the SolutionInn App