Write your code: Even or Odd?
Contents
Write your code: Even or Odd?#
Write a function that returns
True
if the number is EvenFalse
if the number is Odd.
Function definition#
def is_even(number):
# write the code here
File "/tmp/ipykernel_2118/4188263978.py", line 3
# write the code here
^
SyntaxError: unexpected EOF while parsing
Testing#
Check if your function returns the expected value using the cell below.
import unittest
from random import randint
class UnitTests(unittest.TestCase):
def test_type(self):
self.assertEqual(type(is_even(randint(-1000,1000))), type(False), 'The function should return a boolean operator')
def test_even(self):
x = N = randint(-1000,1000)*2
self.assertEqual(is_even(x), True, 'Should return `True` for %d' %x)
def test_odd(self):
x = N = randint(-1000,1000)*2 + 1
self.assertEqual(is_even(x), False, 'Should return `False` for %d' %x)
unittest.main(argv=[''], verbosity=2,exit=False)