Coding basics · 1 of 20
Even or odd
Return True if the number n is even, False if it's odd.
What you need
Your code goes inside the function, indented under def. return hands the answer back. % gives the remainder after dividing, and == compares two values, giving True or False.
def isEven(self, n):
remainder = n % 2 # 7 % 2 is 1
return remainder == 0Examples
Input n = 4
Output True
Input n = 7
Output False
Input n = -10
Output True
Negative numbers can be even too.