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.


10 comments
Adex Elizy
def is_even(number):
if number % 2 == 0:
return True
else:
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
print("YOUR CODE IS CORRECT!")


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

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

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???

https://repl.it/FBF7/2

What does it mean??
zihad
https://repl.it/Ewhr/0
Åsmund Kirkevold
I did excactly the same thing as you, but I got an error.. https://trinket.io/python/00b350fce9
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