Question: Having trouble with the folowing. I needed to write code based on the specification below but I am confused on the specifications given. A hint

Having trouble with the folowing. I needed to write code based on the specification below but I am confused on the specifications given. A hint was given: You are going to want to use the double-accumulator pattern for this problem. The outside for-loop accumulates the list to return. Inside of the for-loop you have an accumulator (and another for-loop) to accumulate the sum for each row. This hint is honestly confusing. I guess would you have several accumulators but then how would you know how many accumulators you need because the list the user inputs would be n length and how would you add element wise : a1 +b1+c1+ d1+ ... + n1?

def row_sums(table): """ Returns a list that is the sum of each row in a table. This function assumes that table has no header, so each row has only numbers in it. Examples: row_sums([[0.1,0.3,0.5],[0.6,0.2,0.7],[0.5,1.1,0.1]]) returns [0.8, 1.5, 1.7] row_sums([[0.2,0.1],[-0.2,0.1],[0.2,-0.1],[-0.2,-0.1]]) returns [0.3, -0.1, 0.1, -0.3] Parameter table: the nested list to process Precondition: table is a table of numbers. In other words, (1) table is a nested 2D list in row-major order, (2) each row contains only numbers, and (3) each row is the same length. """ sum1 = 0

for element in table:

sum2 = 0

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock 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 Databases Questions!