*Data Structures and Algorithms in Python*.I am working on an exercise that involves writing a function that returns true on the passing parameter being even. Constraints are you may not use modulo, multiplication, or division.

I have writting the following:

# define function to determine if integer parameter is even or odd # return true on even. return false on odd. def is_even(val): print(val) # used to ensure val is decrementing val = int(val) - 2 if val == 0: print('Hits True') # used to ensure if statement is working return True if val == 1: print('Hits False') return False is_even(val) # recursive method to decrement the value num = int(input('Enter a number to determin if number is even: ')) print('IS_EVEN RETURNS {1} on the number {0}'.format(num, is_even(num)))

The comments included are for debugging.

outputs:

Quote

2

Hits True

IS_EVEN RETURNS True on the number 2

3

Hits False

IS_EVEN RETURNS False on the number 3

Hits True

IS_EVEN RETURNS True on the number 2

3

Hits False

IS_EVEN RETURNS False on the number 3

Now is the strange part...

Quote

4

2

Hits True

IS_EVEN RETURNS None on the number 4

5

3

Hits False

IS_EVEN RETURNS None on the number 5

2

Hits True

IS_EVEN RETURNS None on the number 4

5

3

Hits False

IS_EVEN RETURNS None on the number 5

I am trying to understand why for numbers 2 and 3 it returns as expected, but None on everything else, including 1. I used a print statement to ensure that the if statement was being passed and yet the return does not return the boolean.

This post has been edited by **astonecipher**: 14 April 2014 - 05:46 PM