I have the following simplest script
inp = input().split() print('inp', inp) l = [] for elem in inp: l.append(int(elem)) print('initial: ', l) for el in l: print(el) if el % 2 != 0: l.remove(el) print('after removing odd numbers: ', l) First input (string):
1 2 3 4 5 6 7 conclusion:
inp ['1', '2', '3', '4', '5', '6', '7'] initial: [1, 2, 3, 4, 5, 6, 7] 1 3 5 7 after removing odd numbers: [2, 4, 6] Second input (string):
10 8 5 3 1 conclusion:
inp ['10', '8', '5', '3', '1'] initial: [10, 8, 5, 3, 1] 10 8 5 1 after removing odd numbers: [10, 8, 3] Screenshot here .
1st I / O
1) Why does the script display only odd items? It must output all elements.
2nd I / O
1) Why is there no number 3 in the output, only 10, 8, 5 and 1?
2) And, therefore, why does the final list contain the number 3?
Thank you