diff --git a/main.py b/main.py index fabba48..ae9ad75 100644 --- a/main.py +++ b/main.py @@ -7,6 +7,13 @@ def divide_by_two(num): # Take last digit, divide by two only on that def divide_by_three(num): # Sum each digit in number, then checking that sum is divisible by three return _sum_digits(num) % 3 == 0 +def divide_by_four(num): # If last two digits are divisible by four + if (num < 10): return num % 4 == 0 + tens_place = _get_last_digit(num, 2) + ones_place = _get_last_digit(num) + num_to_check = (tens_place * 10) + ones_place + return num_to_check % 4 == 0 + def divide_by_five(num): # If last digit is a zero or a five return true last_digit = _get_last_digit(num) return last_digit == 0 or last_digit == 5 @@ -18,8 +25,8 @@ def divide_by_six(num): # Same rules as dividing by three, and ensure original n def divide_by_nine(num): # Same rules as dividing by three, but checking that sum is divisible by nine return _sum_digits(num) % 9 == 0 -def _get_last_digit(num): - return int(f"{num}"[-1]) +def _get_last_digit(num, indexFromEnd = 1): + return int(f"{num}"[-1 * indexFromEnd]) def _sum_digits(num): num_string = f"{num}" diff --git a/tests/four_test.py b/tests/four_test.py new file mode 100644 index 0000000..9451a27 --- /dev/null +++ b/tests/four_test.py @@ -0,0 +1,18 @@ +from main import divide_by_four +import unittest + +class TestDivideByTwo(unittest.TestCase): + def test_by_1(self): + self.assertFalse(divide_by_four(1)) + def test_by_2(self): + self.assertFalse(divide_by_four(2)) + def test_by_3(self): + self.assertFalse(divide_by_four(3)) + def test_by_4(self): + self.assertTrue(divide_by_four(4)) + def test_by_5(self): + self.assertFalse(divide_by_four(5)) + def test_by_8(self): + self.assertTrue(divide_by_four(8)) + def test_by_362880(self): + self.assertTrue(divide_by_four(362880))