209k views
3 votes
The list of lists below is meant to represent the money raised by a charity over multiple days. The inner lists represent each donation, and the outer list represents each day. Use a for loop to calculate the sum of all the numbers in this list of list of numbers, to print the total amount of money raised.

code given:hourly_donations_per_day = [[44, 33, 56, 27, 33, 25],[12, 15, 22, 19, 21],[36, 34, 32, 37, 28, 11, 35],[20, 19, 29],[22, 27, 21, 15, 26, 15]]

1 Answer

5 votes

Answer:

Following are the code to this question:

hourly_donations_per_day = [ #declaring list of lists and assign values

[44, 33, 56, 27, 33, 25],

[12, 15, 22, 19, 21],

[36, 34, 32, 37, 28, 11, 35],

[20, 19, 29],

[22, 27, 21, 15, 26, 15]

]

total_amount_of_money_raised = 0#defining a variable and assign a values 0

for i in hourly_donations_per_day:#defining loop to count values donation

if isinstance(i,list): #using if block to add donation values

for j in i:#defining loop for add list values

total_amount_of_money_raised += j #add all values in total_amount_of_money_raised variable

print(total_amount_of_money_raised) #print value

Output:

714

Step-by-step explanation:

  • In the above code, a list of the list is declared in which, it assigns the multiple values, in the inner lists it represents donation value and in the outer list it represents the day.
  • In the next step, a variable "total_amount_of_money_raised" is declared that assigns a value 0, in the next step, multiple for loop is declared which is used to add list donation value and at the last print, the method is used to print its value.
User Brian Gillespie
by
6.4k points