Loop Challenge, please find the bug :)

Hi Everybody, just tried another version of code for the Code Challenge 3 in the Chapter loops… See link and code below… Somehow it does not work although theoretically it should work… Does anyone find the bug ?? Thank you very much


def delete_starting_evens(lst):
for number in lst:
if number % 2 == 0:
return lst

It would be handy is you could format the code for the forums- How do I format code in my posts? as the missing indentation makes it difficult to work out how your code is structured.

I assume at the moment something like delete_starting_evens([1, 2, 3]) produces a result of [2, 3]; is that right?

Could you explain, why the code stops here at number 10??

Altering the collection you’re iterating through will often cause problems. It’s like trying to count the number of people in a line when the number of people keeps changing and they keep shuffling around. It’s just very hard to keep track of.

It might be best to find a solution that doesn’t directly alter the list you’re iterating through inside a for loop.

You’d want to use the formatting in the following way (the python bit isn’t strictly necessary)-

code goes here