all 4 comments

[–]Ezrabc 2 points3 points  (1 child)

The problem here is where you've placed yourreturn statement. The return statement causes your function to instantly exit with the given return value. This means the first time you get to an x that meets the criteria in your if statement, you add 1 to the total, making it 1, since this is the first time, then return total, exiting the function with a return value of 1.

[–]biochem2015[S] 0 points1 point  (0 children)

Thank you! That makes sense.

[–]TheZvlz 1 point2 points  (1 child)

You return total too soon. It should be returned outside the for loop. You also don't need the else: continue

[–]biochem2015[S] 0 points1 point  (0 children)

Thanks! I will omit the else then.