I'm testing this to count the number of even numbers vs the number of odd numbers in the first 3 elements of an array.
This works:
for i in range(3):
if int(numbers[i]) % 2 == 0:
ev +=1
else:
od +=1
print(ev, od)
But this gives me an error:
for i in range(3):
ev += 1 if numbers[i] % 2 == 0 else od += 1
print(ev, od)
ev += 1 if numbers[i] % 2 == 0 else od += 1
^
SyntaxError: invalid syntax
Any ideas?