mynumbers=[0,1,0,1,6,0,2,0,9]
def sum(mynumbers):
total = 0
for x in mynumbers:
total =1+x
return total
print(sum(mynumbers))
I do like that but I want to find the sum in list type
how I find sum of number in list ?
mynumbers=[0,1,0,1,6,0,2,0,9]
def sum(mynumbers):
total = 0
for x in mynumbers:
total =1+x
return total
print(sum(mynumbers))
I do like that but I want to find the sum in list type
how I find sum of number in list ?
I'm not sure what you are wanting here, but given your current function, do this:
>>> myNumbers = [0,1,0,1,6,0,2,0,9]
>>> sum(myNumbers)
19
The built-in sum()
method works on an iterable already.