Write a Python function that takes a list of integers as a parameter and returns the sum of the elements in the list. Thank you.
Code for required function:
# Function to take list of integers and return sum
def sum_of_list(list1):
# Calculating sum of elements in list
sum1 = sum(list1)
# Returning sum
return sum1
Example
Code(With calling function):
# Function to take list of integers and return sum
def sum_of_list(list1):
# Calculating sum of elements in list
sum1 = sum(list1)
# Returning sum
return sum1
# Calling function here
# Change your list here
print(sum_of_list([1,2,3,4,5]))
Output:
Get Answers For Free
Most questions answered within 1 hours.