r/shittyprogramming • • Apr 27 '21

5 Line "is_even" Function

I've attempted to solve the infamous "is even" problem, and I've come up with something that is both short (only 5 lines), and extremely fast (I tested with the number 99999999 and it only takes about 0.1 seconds)

behold:

def is_even(num):
    if num%2 == 0:
        print('Even Number')
    else:
        print('Odd')
9 Upvotes

5 comments sorted by

View all comments

Show parent comment

1

u/[deleted] May 18 '21
is_even=lambda n:(n==0)or n>0and is_even(n-2)