Https://www.codecademy.com/courses/learn-python-3/lessons/python-functions-loops-cc/exercises/remove-even-nums

https://www.codecademy.com/courses/learn-python-3/lessons/python-functions-loops-cc/exercises/remove-even-nums

#Write your function here

def delete_starting_evens(lst):

  while (len(lst) > 0 and lst[0] % 2 == 0):

    lst = lst[1:]

  return lst

#Uncomment the lines below when your function is done

print(delete_starting_evens([4, 8, 10, 11, 12, 15]))

print(delete_starting_evens([4, 8, 10]))

I do not understand the use of while loop in function? Please, elaborate on it.

A while loop cotinutally loops whilst the conditional expression evaluates to True. So in this case loop while (len(lst) > 0) and (lst[0] % 2 == 0 ) are both equivalent to True. If you’re not familiar with the modulo operator you may need to look into it quickly but it returns remainders from division, e.g.

7 % 3  # Out: 1
# A quotient of 2 and a remainder of 1
0 % 3  # Out: 0
# Zero quotient, zero remainder
2 Likes