Building Software I 2559
Saturday, September 26, 2015
Lab5 - Find sum of positive values in array
def find_sum(n):
i=0
sum=0
while(i<len(n)):
if(n[i]>0):
sum=sum+n[i]
i+=1
return sum
def setup():
n=[5,8,-9,7,5,3,-2,9]
print("Sum of values in array",find_sum(n))
setup()
No comments:
Post a Comment
Newer Post
Older Post
Home
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment