Try it on paper first. A hint, the key idea and the worked solution are here when you need them.
Write a function is_even(n) that returns True if n is even, and False if it is odd. What does it return for and ?
A comparison gives True or False, so a function can return it.
Have you tried it?
Work it out on paper first. It is fine to get stuck or make a mistake: that is how we learn. When you are ready, compare your working with the solution.
Plan. An even number leaves remainder 0 when divided by 2. The comparison n % 2 == 0 is already True or False, so the function can return it directly.
is_even(14) is True.is_even(7) is False.Log in to join the discussion.
Loading…