By eight
This commit is contained in:
parent
715ae7bf4c
commit
cddde3aa52
3 changed files with 35 additions and 5 deletions
16
main.py
16
main.py
|
@ -7,11 +7,11 @@ 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
|
def divide_by_three(num): # Sum each digit in number, then checking that sum is divisible by three
|
||||||
return _sum_digits(num) % 3 == 0
|
return _sum_digits(num) % 3 == 0
|
||||||
|
|
||||||
def divide_by_four(num): # If last two digits are divisible by four
|
def divide_by_four(num): # If last two digits are divisible by four, plus a simplifier of multiplying the tens place by two
|
||||||
if (num < 10): return num % 4 == 0
|
if (num <= 10): return num % 4 == 0
|
||||||
tens_place = _get_last_digit(num, 2)
|
tens_place = _get_last_digit(num, 2) * 10
|
||||||
ones_place = _get_last_digit(num)
|
ones_place = _get_last_digit(num)
|
||||||
num_to_check = (tens_place * 10) + ones_place
|
num_to_check = (tens_place * 2) + ones_place
|
||||||
return num_to_check % 4 == 0
|
return num_to_check % 4 == 0
|
||||||
|
|
||||||
def divide_by_five(num): # If last digit is a zero or a five return true
|
def divide_by_five(num): # If last digit is a zero or a five return true
|
||||||
|
@ -22,6 +22,14 @@ def divide_by_six(num): # Same rules as dividing by three, and ensure original n
|
||||||
num_sum = _sum_digits(num)
|
num_sum = _sum_digits(num)
|
||||||
return num_sum % 3 == 0 and divide_by_two(num)
|
return num_sum % 3 == 0 and divide_by_two(num)
|
||||||
|
|
||||||
|
def divide_by_eight(num): # Same rules as dividing by four, but for last three digits
|
||||||
|
if (num <= 100): return num % 8 == 0
|
||||||
|
hundreds_place = _get_last_digit(num, 3) * 100
|
||||||
|
tens_place = _get_last_digit(num, 2) * 10
|
||||||
|
ones_place = _get_last_digit(num)
|
||||||
|
num_to_check = (hundreds_place * 4) + (tens_place * 2) + ones_place
|
||||||
|
return num_to_check % 8 == 0
|
||||||
|
|
||||||
def divide_by_nine(num): # Same rules as dividing by three, but checking that sum is divisible by nine
|
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
|
return _sum_digits(num) % 9 == 0
|
||||||
|
|
||||||
|
|
22
tests/eight_test.py
Normal file
22
tests/eight_test.py
Normal file
|
@ -0,0 +1,22 @@
|
||||||
|
from main import divide_by_eight
|
||||||
|
import unittest
|
||||||
|
|
||||||
|
class TestDivideByEight(unittest.TestCase):
|
||||||
|
def test_by_1(self):
|
||||||
|
self.assertFalse(divide_by_eight(1))
|
||||||
|
def test_by_2(self):
|
||||||
|
self.assertFalse(divide_by_eight(2))
|
||||||
|
def test_by_4(self):
|
||||||
|
self.assertFalse(divide_by_eight(4))
|
||||||
|
def test_by_8(self):
|
||||||
|
self.assertTrue(divide_by_eight(8))
|
||||||
|
def test_by_10(self):
|
||||||
|
self.assertFalse(divide_by_eight(10))
|
||||||
|
def test_by_16(self):
|
||||||
|
self.assertTrue(divide_by_eight(16))
|
||||||
|
def test_by_100(self):
|
||||||
|
self.assertFalse(divide_by_eight(100))
|
||||||
|
def test_by_800(self):
|
||||||
|
self.assertTrue(divide_by_eight(800))
|
||||||
|
def test_by_362880(self):
|
||||||
|
self.assertTrue(divide_by_eight(362880))
|
|
@ -1,7 +1,7 @@
|
||||||
from main import divide_by_four
|
from main import divide_by_four
|
||||||
import unittest
|
import unittest
|
||||||
|
|
||||||
class TestDivideByTwo(unittest.TestCase):
|
class TestDivideByFour(unittest.TestCase):
|
||||||
def test_by_1(self):
|
def test_by_1(self):
|
||||||
self.assertFalse(divide_by_four(1))
|
self.assertFalse(divide_by_four(1))
|
||||||
def test_by_2(self):
|
def test_by_2(self):
|
||||||
|
|
Loading…
Add table
Reference in a new issue