This is the goal: “This function repeatedly removes the first element of a list until it finds an odd number or runs out of elements. It will accept a list of numbers as an input parameter and return the modified list where any even numbers at the beginning of the list are removed.”
Can someone please explain why this function does not work?
If the image did not show up, this was my solution:
def delete_starting_evens(lst):
for num in lst:
if num % 2 == 0:
lst.pop(0)
return lst
When I printed these:
print(delete_starting_evens([4, 8, 10, 11, 12, 15]))
print(delete_starting_evens([4, 8, 10, 12, 15]))
The output was:
[11, 12, 15]
[10, 12, 15]
It’s problem number 3 on this page
https://www.codecademy.com/paths/computer-science/tracks/cspath-cs-101/modules/cspath-code-challenges/articles/python-code-challenges-loops