Comprehensions and functional programming · 7 / 15 Exercise Easy

Filter even numbers

Objective

Create a Python program that keeps only the even numbers of a list using a comprehension with a condition.

Instructions

  • Read a line with integers separated by spaces and turn it into a list of integers with a comprehension.
  • With another comprehension with if, get only the even numbers.
  • Show the even numbers on a single line, separated by a space, in the same order in which they appear.
  • If there is no even number, show None.
Input
1 2 3 4 5 6
Output
2 4 6

Open the editor in full screen: the statement on the left and your code, the output and the tests on the right.

Start exercise