125k views
5 votes
Write the definition of a function named sum_list that has one parameter, a list whose elements are of type int. The function returns the sum of the elements of the list as an int.

User Visar
by
5.8k points

1 Answer

6 votes

Answer:

The code to the given question can be given as:

Code:

def sum_list(a): #define function.

return sum(a) # return sum of elements.

Step-by-step explanation:

In the above python programming language code firstly we define a function that is "sum_list()" to define any function we use the def keyword.

In this function, we pass one parameter that is "a" add all elements in the list. To add this number we use the sum function it is the inbuilt function that returns the sum of the elements of the list as an int.

User Jcragun
by
5.9k points