Ask Question
19 December, 06:07

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
Answers (1)
  1. 19 December, 06:27
    0
    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

    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.
Know the Answer?
Not Sure About the Answer?
Find an answer to your question 👍 “The list of lists below is meant to represent the money raised by a charity over multiple days. The inner lists represent each donation, ...” in 📗 Computers & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers