return the biggest even fro a list python 1

return the biggest even fro a list python

b=[10,30,40,88,77,99,12515,365,959,48,8595,95,9,59,59,5,9,9,49,5,548485844842]
def is_even(lis) :
    i=len(lis)-1
    lis.sort()
    while max(lis)%2!=0:
        i=i-1
        if lis[i]%2==0:
            break
    return lis[i]
print(is_even(b))

Here is what the above code is Doing:
1. It is sorting the list in ascending order.
2. Then it is checking if the last element is even or not.
3. If it is even, it returns the last element.
4. If it is not even, it checks the second last element.
5. It keeps on checking the elements until it finds an even number.
6. If it doesn’t find an even number, it returns None.

Similar Posts