0
Why it hasnot add the even to the list and print true and false and in the last..[] !!!
4 Respostas
+ 1
Because you function needs to return true when x even and false when x odd
Try
def isEven(x):
Print(x%2==0)
return x%2 == 0
+ 1
Because the function filters the list checking if the condition is true to fix your problem you can forget the filter and just do
lis = [...]
def is_even(num):
print(num % 2 == 0)
for elem in lis: is_even(elem)
+ 1
Filter goes through the list and applies the function to the list and the expects the function to return a Boolean value to filter, if it sees a that the function returned true it appends the element of the list it is looking at to the list it will output after it is finished looking through the list you gave to it as input
0
but why it need to return ?