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.
# sum function to calculate the total of all elements in the
given list
def sum(lst):
total=0
for j in lst:
total=total+j
return total
lst=[]
size=int(input("Enter the size of list: "))
# reading elements into the list from keyboard
for i in range(size):
num=int(input("Enter your number: "))
lst.append(num);
result=sum(lst) #function call
print("sum of all elements in the given list is :",result)
Screenshots:
Output:
Get Answers For Free
Most questions answered within 1 hours.