So the problem is asking me to return the sum of even or odd elements in a list given the condition odd or even. So if the condition is odd, I have to return a list of all odd numbers. If the list is blank/the values do not match the condition, then return 0.
This is what I have so far:
l = [1,2,3,4,5,6]
def conditionalSum(value, condition):
s = 0
if condition == "even":
for i in l:
if i % 2 == 0:
s += i
elif condition == "odd":
for i in l:
if i % 2 !=0:
s = s+ i
else:
return 0
When I try to run this, nothing comes up - not even an error! Any help is appreciated