30 lines
1,012 B
Python
30 lines
1,012 B
Python
def divide_by_one(num): # Is whole number
|
|
return float(num).is_integer()
|
|
|
|
def divide_by_two(num): # Take last digit, divide by two only on that
|
|
return _get_last_digit(num) % 2 == 0
|
|
|
|
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_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
|
|
|
|
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
|
|
|
|
def _get_last_digit(num):
|
|
return int(f"{num}"[-1])
|
|
|
|
def _sum_digits(num):
|
|
num_string = f"{num}"
|
|
num_sum = 0
|
|
for digit_char in num_string:
|
|
num_sum += int(digit_char)
|
|
return num_sum
|
|
|