A number is odd if it is not evenly divisible by 2, which means we should make use of the modulo % operator. The modulo operator returns the remainder after devision, so if something is evenly divisible by 2, with a remainder of 0, it isn’t odd! if my_number % 2 == 0: means a number is even.
.remove() is not the right approach to solve this problem, removing from the same list as you are looping over causes undesired behavior, like skipping successive odd/uneven numbers.
logic variable naming is important, char seemed to indicate a character, in which case you can use list(), which i why i think mtf included list(char) in his answer, but only mtf himself can answer that
This is how we learn about exceptions and errors (by doing it)
>>> list(1)
Traceback (most recent call last):
File "<pyshell#349>", line 1, in <module>
list(1)
TypeError: 'int' object is not iterable
>>> a = []
>>> a += [1]
>>> a
[1]
>>>
mutating a list where you are looping over is a recipe for disaster,
lists can’t have empty spaces/slots, so when you remove an item everything to the right of the removed elements moves one to the left, combined with the loop (which goes to the next index), values will get skipped
why can you .append() an integer but you can’t .remove() it? if you use .remove() in a for loop i mean yes, it will remove that value at the index and all the other value at the indices will move left and values will be skipped, but since it’s a for loop wouldn’t it re-iterate through it again until the condition is fully met? or is that ability acquired in a while loop?
the loop keeps track of the current position/index. So not possible. So the loop will go from the first element, to the second element and so forth. Not caring about the shifts happening in the list
what do you mean current index, the index you input? what is specifically happening in the loop that generates that error when you use .remove() in the loop; and when you say not caring about the shifts happening in the list, is that indicating it won’t iterate through the list more than once to be able to get every value intended, because for that to happen your return would have to be inside the for loop…so consider my question with everything being correctly where it’s supposed to be, and i’m using .remove()