# threeVersionsIsEven.py P. Conrad for CS5nm, 11/10/08 # Three different ways to write isEven. # All of these will produce the same results # The shortest version def isEven(n): return (n%2==0) # This version is just longer def isEven_v2(n): if (n%2==0): return True else: return False # This version uses the fact that # once you return a value, the function call is over. # So the only way that the function reaches the line "return False" # is when we didn't return True, so the "else" is actual unnecessar def isEven_v3(n): if (n%2==0): return True return False # A way to quickly write isOdd, given that we already have isEven def isOdd(n): return not isEven(n)