+ 1
print(" ".join([i for i in input().split() if int(i)%2==0]))
https://code.sololearn.com/c3LX0QtX8r4Z/?ref=app
+ 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])
+ 1
Aysha , and your code is correct and no any confuses?
How many line your code will print out? Huh
0
#Ruby
s = gets.chomp.split(" ")
s.each do |x|
print "#{x} " if x.to_i % 2 == 0
end
0
Shadoff teach me one liner solution đ„čđ„ș