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.


16 comments
Jackson AIken
https://repl.it/FqlV/0
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

else:
return False



is_number_divisible(10, 3)

print(is_number_divisible(9, 3))

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


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

print(is_even(10))
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
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