Q:

Type error: unsupported operand

I'm trying to write a code that takes in a number and returns the sum of the digits raised to the power of its corresponding position.
Example: >>>534 returns 5^1 + 3^2 + 4^3. 

7

My code works for range of numbers below 100. It fails for 3-digit numbers with the error message: TypeError: Unsupported operand type(s) for +: 'int' and 'NoneType'
My code bellow. I apologize in advance for poorly structured code. I'm just a beginner. Thank you.
def sum_dig_pow(a, b):
    dict1 = {}
    for k in range(a,b+1):
        if k < 10:
            dict1[k] = k**1

        else:
            num_len = int(len(str(k))) + 1

            def dig_pow(k):
                nonlocal num_len
                num_len -= 1
                if k < 10:
                    return k
                else:
                    var = (k%10)**num_len + dig_pow(k//10)
                    dict1[k] = var

            dig_pow(k)
    return dict1
print(sum_dig_pow(98, 100))

A:

It's minutely less efficent, but I think that treating your input number as a string, then iterating through it is simpler to understand then seperating the digits mathematically.
def dig_pow(n):
    return sum(int(digit)**position for position, digit in enumerate(str(n), start=1))

dig_pow(534)
# 78

