six
This commit is contained in:
parent
3873020e15
commit
4fb6a5fb8f
2 changed files with 24 additions and 2 deletions
8
main.py
8
main.py
|
@ -4,14 +4,18 @@ def divide_by_one(num): # Is whole number
|
||||||
def divide_by_two(num): # Take last digit, divide by two only on that
|
def divide_by_two(num): # Take last digit, divide by two only on that
|
||||||
return _get_last_digit(num) % 2 == 0
|
return _get_last_digit(num) % 2 == 0
|
||||||
|
|
||||||
def divide_by_three(num): # Sum each digit in number, then check divisibility of that number
|
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_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
|
||||||
last_digit = _get_last_digit(num)
|
last_digit = _get_last_digit(num)
|
||||||
return last_digit == 0 or last_digit == 5
|
return last_digit == 0 or last_digit == 5
|
||||||
|
|
||||||
def divide_by_nine(num): # Sum each digit in number, then check divisibility of that number
|
def divide_by_six(num): # Same rules as dividing by three, and ensure original number is even
|
||||||
|
num_sum = _sum_digits(num)
|
||||||
|
return num_sum % 3 == 0 and divide_by_two(num)
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
def _get_last_digit(num):
|
def _get_last_digit(num):
|
||||||
|
|
18
tests/six_test.py
Normal file
18
tests/six_test.py
Normal file
|
@ -0,0 +1,18 @@
|
||||||
|
from main import divide_by_six
|
||||||
|
import unittest
|
||||||
|
|
||||||
|
class TestDivideBySix(unittest.TestCase):
|
||||||
|
def test_by_1(self):
|
||||||
|
self.assertFalse(divide_by_six(1))
|
||||||
|
def test_by_2(self):
|
||||||
|
self.assertFalse(divide_by_six(2))
|
||||||
|
def test_by_3(self):
|
||||||
|
self.assertFalse(divide_by_six(3))
|
||||||
|
def test_by_6(self):
|
||||||
|
self.assertTrue(divide_by_six(6))
|
||||||
|
def test_by_10(self):
|
||||||
|
self.assertFalse(divide_by_six(10))
|
||||||
|
def test_by_12(self):
|
||||||
|
self.assertTrue(divide_by_six(12))
|
||||||
|
def test_by_362880(self):
|
||||||
|
self.assertTrue(divide_by_six(362880))
|
Loading…
Add table
Reference in a new issue