Sep-29-2018, 02:47 AM
(This post was last modified: Sep-29-2018, 03:05 AM by Maximuskiller78.)
Hi guys, I'm trying to return the summation of all even numbers, but the function won't return anything unless the parameter "y" is an odd number.
I fixed it by removing the elif statment.
def sumOfEvens(x,y): total = 0 while x <= y: if (x % 2 == 0): total = (total + x) elif (x == y): return total x = (x + 1)
I fixed it by removing the elif statment.
def sumOfEvens(x,y): total = 0 while x <= y: if (x % 2 == 0): total = (total + x) x = (x + 1) return total