12/15 Practice Makes Perfect: code won't run / load



I was trying to run my code, but it would take ages to load then give me an error with no message. It happens whatever I do to my code, so it’s got to be a problem with the actual thing, however, here is my code:

def purify(numbers):
  purify = []
  for odd in numbers:
    if odd % 2 == 0:
  return purify

Is there anything I could do? Thanks!


you created yourself an infinity loop, that will take ages to loop

by appending to the list you are looping over, the list will never end and thus the loop never ends


How can I tell it to stop once it’s looped through all the numbers? I thought it already does that.


And also, the reason why I don’t think thats the case is because when I remove the for loop, still happens, when I remove half the code or make it so it just wont work, still happens.


it does, but if you are append to the same list as you are looping over, after the loop is done, it got new numbers to loop over

the question you should have asked yourself is: why i am appending to list i am looping over and is this right?


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.