If you're allowed to do things like str(n) or list*k, or even * at all, it kind of defeats the purpose of the exercise
def super_digit_sum (n, k):
return sum (map (int, list (str (n)))) * k
print (super_digit_sum (148, 3)) # 39
But I'm sure the point of this is to use primitive features and operations as a means of learning how to write simple recursive programs...
We start with a simple function that sums the digits of a single input number
def sum_digits (n):
if n < 10:
return n
else:
return n % 10 + sum_digits (n // 10)
print (sum_digits (148))
# 13
Then we make a simple function that can multiply two numbers
def mult (n, m):
if n is 0:
return 0
else:
return m + mult (n - 1, m)
print (mult (3, 7))
# 21
Then combining the two, we write your main function
def super_digit_sum (n, k):
return mult (sum_digits (n), k)
print (super_digit_sum (148, 3))
# 39
If you're allowed to use *, you can skip mult altogether and simply write
def super_digit_sum (n, k):
return sum_digits (n) * k
print (super_digit_sum (148, 3))
# 39
This is a better program because you arrive at the answer in a straightforward manner. Compare that to the other approach of taking a number, converting it into a string, chopping it up into single characters, converting those characters back to digits, then summing the digits, and finally multiplying the result by a constant.
Both approaches arrive at the same result, but only one results in a program worth reading, imo. I talk about this roundabout-style of programming in another python Q&A: How to count neighbors in a list? I think you will find it helpful.
snake_caseinstead oflowerCamelCase. You should name your functionsuper_digit_suminstead ofsuperDigitSum.