Ask Question
12 August, 18:03

Write a function that accepts a list as an argument (assume the list contains integers) and returns the total of the values in the list.

+3
Answers (1)
  1. 12 August, 18:57
    0
    def listSum (mylist):

    sum = 0

    for item in range (0, len (mylist)):

    sum=sum+mylist[item]

    print (sum)

    Explanation:

    Using the Python programming language, I defined a function as listSum that accepts a list as a parameter and returns the sum of the elements in the list.

    The most important logic here is defining the range of elements in the list not to exceed the length of the list using the len function. Then using a for statement, we loop through each element and add them up to a sum variable initially assigned the value of 0.
Know the Answer?
Not Sure About the Answer?
Find an answer to your question ✅ “Write a function that accepts a list as an argument (assume the list contains integers) and returns the total of the values in the list. ...” in 📘 Computers and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers