But unfortunately it shows the following error Can you please tell me what the error means and how can I fix the error?
You are getting TypeError exception at if n % 2 == 0: as interpreter is trying to apply formatting using %. input() returns a str object and if you pass it to list constructor, it will form a list of characters in your string.
Therefore, numbers=list(input("Please enter numbers:")) will be forming a list of str objects (For example, if you pass 1 2 3 to your program, it will convert it to a list of str object: ['1', ' ', '2', ' ', '3']).
You need to convert them to int using int constructor. If you can just change the first line in your program to numbers=list(map(int, input("Please enter numbers: ").split(" "))), it will start working
Try this:
numbers=list(map(int, input("Please enter numbers: ").split(" ")))
def is_even_num():
enum = []
for n in numbers:
if n % 2 == 0:
enum.append(n)
return enum
print(is_even_num())
Pythonic way of doing the same thing using list comprehension:
print([i for i in map(int, input("Please enter the number: ").split(" ")) if not i % 2])