0

List of Even numbers below a certain value in python.

List of Even numbers in python

Topic – List of Even numbers below a certain value in python

EXPLANATION:

For example, if k = 16, your function should return a list of [2,4,6,8,10,12,14]

Name your function as even_list() that takes one argument named k.In [ ]:

# hints:
# you can create an empty list and append items on it by the following code:

a = []
a.append(4)
a.append(6)
print(a)
[4, 6]

In [4]:

let’s start – List of Even numbers below a certain value in python

List of Even numbers in python – CODE

# Implementation

# write your code below
def even_list(k):
    even = []
    for i in range(1,k):
        if i % 2 == 0:
            even.append(i)
    return even

In [5]:

# test your function here
even_list(16)

Out[5]:

[2, 4, 6, 8, 10, 12, 14] 

If you have another efficient method, please share the comment section.

If you also use Python or any other language to complete the job. Share it in the comment section to help others

keep visiting : shaadcoding

shaad

Leave a Reply

Your email address will not be published. Required fields are marked *