samedi 27 novembre 2021

Why does cycle 'if' delete not all odd numbers from the list (only each second odd number)?

There is a code:

list = [1, 2]

while list[-1]+list[-2] <= 4000000:
    list.append(list[-1] + list[-2])
for i in list:
    if i % 2 == 1:
        print(i)
        list.remove(i)
print(list)
print(sum(list))

Aucun commentaire:

Enregistrer un commentaire