This is my code:
def sum_even(a, b):
count = 0
for i in range(a, b, 1):
if(i % 2 == 0):
count += [i]
return count
An example I put was print(sum_even(3,7)) and the output is 0. I cannot figure out what is wrong.
Your indentation is off, it should be:
so that
return countdoesn’t get scoped to your for loop (in which case it would return on the 1st iteration, causing it to return 0)(And change
[i]toi)NOTE: another problem – you should be careful about using
range:so if you were to do calls to:
sum_even(3,7)sum_even(3,8)right now, they would both output
10, which is incorrect for sum of even integers between 3 and 8, inclusive.What you really want is probably this instead: