Previous Lecture Complete and continue  

  Check Is Even

Notes to Help You

  • Functions start with def
  • Don't forget your colons
  • Always return in functions rather than print!

Example Problem.
Write a function add_two that takes in two numbers as input and returns their sum.

Adex Elizy
def is_even(number):
if number % 2 == 0:
return True
return False

# DO NOT remove lines below here,
# this is designed to test your code.

def test_is_even():
assert is_even(2) == True
assert is_even(3) == False
assert is_even(8) == True
assert is_even(100) == True
assert is_even(101) == False

Everything is correct but it's not printing out YOUR CODE IS CORRECT
you miss the part after all --> test_is_even()
Kevin Klein Nagelvoort
def is_even(number):
return number % 2 == 0

Phuc Le
def is_even(number):
return number%2==0
Adex Elizy
>>> 10 % 5 == 0

just one line
Joshua Roxas
def is_even (number):
return number % 2 = false
return number % 1 = true
am I the only one that got confused and put this
Sebastian Gomez
File "python", line 3, in is_even
File "python", line 2, in is_even
RecursionError: maximum recursion depth exceeded in comparison

I get that error when I try to run the first code with is_even(anyevennumber).... the first line of the error are repeated a lot and then it comes the last part. What does that mean???

What does it mean??
Åsmund Kirkevold
I did excactly the same thing as you, but I got an error..
Tara Fahey
There's no if statement nor a colon at the end of line 26. When Python ran the code it was confused as to why line 27 (the code that returns the True statement) was indented