I’m a beginner in Python and have been stuck on this task all afternoon & could do with a bit of help!
The following function should go through all the integers in the argument list, count the number of even integers (i.e. integers divisible by 2), and return that count e.g.
The start of code I’ve been given goes as follows. Everything I’ve tried doesn’t seem to work
** while number from integers**
** if number % 2 = 0**
** count + 1**
** return counter**
Any help is appreciated!
why do you use a while loop? a while is useful for a unknown amount of iterations, but given your program iterates over a list, the amount of iterations is known (number of elements in the list), so using a for loop makes more sense
if number % 2 = 0
a single equal sign means assign, here you want to check if the remainder equals zero, how could this be achieved?
count + 1
what is the name of the variable you are going to use? count or counter? you have to choice
where is count/counter defined? I don’t see it defined anywhere
at the end of if condition there should be a colon (
if condition:), i don’t see the colon anywhere? This colon also needs to be at the end of our loop condition
please run this code:
i = 1
i + 1
i doesn’t increase? we really need to update the variable, how could we achieve this?
There are so many mistakes in your code, i hope i covered them all. Are you sure you are not doing something which is out of your league? If you need more help, post an updated version of your code
I’ve not written this code, this is the code I’ve been given to ‘complete’ the program
well, i suggested what you needed to change, and also told you what to do when you need more help