List Comprehension Basics

Easy
13
88.9% Acceptance

In this lab, you will create a Python function named list_even_numbers. This function will generate a list of even numbers within a specified range using list comprehension.

Function Requirements

  • Function Name: list_even_numbers
  • Parameter: An integer n
  • Return Value: A list of even numbers from 1 to n (inclusive), generated using list comprehension.

Examples

  • list_even_numbers(5) should return [2, 4].
  • list_even_numbers(10) should return [2, 4, 6, 8, 10].

Your task is to ensure that this function works correctly for various values of n, as it will be tested against predetermined test cases. Focus on correctly applying list comprehension to generate the required list of even numbers.