Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

QUESTION 1: Complete the function below that takes a Python list as an argument. You can assume the list will only contain numbers. Use a

QUESTION 1:

Complete the function below that takes a Python list as an argument. You can assume the list will only contain numbers. Use a for- or while-loop to compute the total (i.e. sum) of all the entries in alist. The function should return only the total. For example, calling the function with

list_sum([1, 2, 3]) 

will return 6

WITHOUT USING THE THE COMMAND SUM()

|def list_sum(alist): return #sum of all entries in list|

QUESTION 2:

Complete the function below that takes a Python list as an argument. You can assume the list will only contain numbers. Use a for- or while-loop to compute the cumulative sum at each entry of the input list. The function should return a list, where each value in the list is the sum of the value in the equivalent index in alist and all those before it in order. For example, calling the function with

cumulative_sum([1, 2, 3]) 

will return [1, 3, 6]. And

cumulative_sum([1, 3, 5, 8]) 

will return [1, 4, 9, 17].

|def cumulative_sum(alist): return #list containing cumulative sums|

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions