aboutsummaryrefslogtreecommitdiff
path: root/challenge-007/lubos-kolouch/python/ch-1.py
blob: 02a91e9edf8f0be5a2aa677de10dfcabf4fd7fb1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
#!/usr/bin/env python
# -*- coding: utf-8 -*-

def sum_of_digits(number: int) -> int:
    """Return the sum of digits of a given number."""
    total = 0
    while number > 0:
        total += number % 10
        number //= 10
    return total


def print_niven_numbers() -> None:
    """Print all the niven numbers from 0 to 50 inclusive."""
    for num in range(51):
        digit_sum = sum_of_digits(num)
        if digit_sum != 0 and num % digit_sum == 0:
            print(num)


if __name__ == '__main__':
    print_niven_numbers()