The task is to create modify_list(l) function, which removes odd numbers from the list and divides even numbers in the list by 2 without remainder.
#My code
lst = [1, 2, 3, 4, 5, 6]
def modify_list(l):
for k in l:
if k%2 == 1:
l.remove(k)
elif k%2 != 1:
l.remove(k)
l.append(k//2)
return l
print(modify_list(lst))
#This is how function is expected to work:
lst = [1, 2, 3, 4, 5, 6]
print(modify_list(lst)) # None
print(lst) # [1, 2, 3]
modify_list(lst)
print(lst) # [1]
#My code returns:
print(modify_list(lst)) #[2, 4, 6] instead of none or at least [1, 2, 3]
So, elif part of code is just ignored! I dont't understand why