+ 1
print(" ".join([i for i in input().split() if int(i)%2==0])) https://code.sololearn.com/c3LX0QtX8r4Z/?ref=app
14th Jul 2021, 2:40 PM
Shadoff
Shadoff - avatar
+ 9
Nikolay , the reason for your issue is that elements in the nums list will be removed during iteration. this will result in index issues. this can be avoided when we use a copy of our list to iterate through: ... for i in nums[:]: ... following the task description that says: â–Ș"Given a list of numbers, you want to TAKE OUT all of the odd ones and LEAVE just the even ones." the above code will do this. â–Șa different approach to get the even values out of the list is to use a list comprehension, but it does not strictly follow the description as it creates a new list: # the code in line 1 starting with < or ...> is just to make input easy for this test. it needs only to press < Return > to pass the numbers to the input() function lst = list(map(int, input().split() or "8 10 19 25 5 16 12".split())) print([num for num in lst if num % 2 == 0])
14th Jul 2021, 6:11 PM
Lothar
Lothar - avatar
+ 1
Aysha , and your code is correct and no any confuses? How many line your code will print out? Huh
14th Jul 2021, 3:04 PM
Shadoff
Shadoff - avatar
0
#Ruby s = gets.chomp.split(" ") s.each do |x| print "#{x} " if x.to_i % 2 == 0 end
29th Sep 2022, 8:32 AM
FELIX IDALIA
FELIX IDALIA - avatar
0
Shadoff teach me one liner solution đŸ„čđŸ„ș
21st Nov 2022, 11:43 AM
Ming
Ming - avatar