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