Problem

Description

Write a function that will take two numbers and return True if one is even, and the other is odd.

Test Cases

Solution

My Solution

def lovefunc( flower1, flower2 ):
    # ...
    return True if flower1 % 2 == 0 and flower2 % 2 == 1 or flower1 % 2 == 1 and flower2 % 2 == 0 else False

Other Solutions

def lovefunc(flower1, flower2):
    return flower1 % 2 != flower2 % 2
def lovefunc( flower1, flower2 ):
    return (flower1+flower2)%2

Learning Experiences

  • The second solution works because it returns either a zero or a one, which (in Python) is equivalent to the Booleans False and True respectively. An odd and even number always equals an odd number, which would return one (True).