Question: 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

Define a function read_data that accepts a single argument corresponding to the filename, and returns a list

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.

Step by Step Solution

3.53 Rating (150 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

It seems that the images still haven... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!