Python 3 Write Function Accept List Return Sum Numbers Example X 10 15 20 12 Sumoflist X W Q37272664

In python 3,

Write a function that will accept a list and return the sum ofall the numbers.

Example:

x=[10,15,20,12]

sumOfList(x) would return 57


Answer


def sumOfList(x): s = 0 for i in x: s += i return s#testingx=[10,15,20,12]print(sumOfList(x)) #would return 57

color{blue}underline{Output:}

57

Please upvote the solution if it helped. Thanks!

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.