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.

Jackson AIken
Easy peasy.
A is just an input variable
Its saying if 'a' is divided by 2 and whatever is left over equals zero then the number is even
def is_even(a):
return a % 2 == 0
Kristian Nielsen-Brøchner
def is_number_divisible(number1, number2):
if number1 % number2 == 0:
return True

return False

is_number_divisible(10, 3)

print(is_number_divisible(9, 3))

print(is_number_divisible(5467, 87))
>>> def test_is_even(number):
if number % 2 == 0:
return True
return False

>>> print(test_is_even(10))
Amal Abdiweli
def is_even(number):
return number % 2==0

Bryson Xiao
I didn't know what to do at first because I didn't know that % was the divisible by thing.
poonam ahir
def num_is_even(number):
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