Project Euler # 56 Powerful digit sum in Python A googol (\$10^{100}\$) is a massive number: one followed by one-hundred zeros; \$100^{100}\$ is almost unimaginably
large: one followed by two-hundred zeros. Despite their size, the sum of the digits in each number is only 1.

Considering natural numbers of the form, \$a^b\$, where \$a, b &lt; 100\$, what is the maximum digital sum?

def get_powers(n):
    """Assumes n a range, generates all numbers to the power of all numbers within the range."""
    for num in range(n):
        for power in range(n):
            yield num ** power


def get_digit_sum(n):
    """Assumes n a number, returns sum of digits."""
    return sum(int(digit) for digit in str(n))


def get_maximum(n):
    """Assumes n a range, gets all a ** b within range, returns max sum digits."""
    return max((get_digit_sum(num) for num in get_powers(n)))


if __name__ == '__main__':
    print(get_maximum(100))
Very nice code! Here are a few small comments, most of which are not something you have to change but rather food for thoughts as you learn more.


Although this is a matter of personal style, I would turn around your docstrings so what is returned comes first, if possible.

I.e. I would write

"""Generates all numbers of the form `a ** b` for `a, b &lt; n`."""
"""Return the sum of digits of the number `n`."""
"""Return the max sum of the digits of all numbers of the form `a ** b` for `a, b &lt; n`."""

If a generator expression is the only argument to a function, one pair of () can be omitted:

return max(get_digit_sum(num) for num in get_powers(n))

Although sometimes discouraged, if you need those last 10% of speed, this is slightly faster since int is a built-in function implemented in C:

def get_digit_sum(n):
    return sum(map(int, str(n)))

Nested for loops can be replaced with itertools.product, although here it is arguably harder to read instead of easier. For high levels of nestedness it can help increase readability, though.

from itertools import product

def get_powers(n):
    for num, power in product(range(n), range(n)):
        yield num ** power