I need to stepwise concatenate the given number at each iteration so that it returns the sum and concatenated string. This is my attempt:
def digit_sum_from_letters(x): a = int("%s" % x) b = int("%s%s" % (x,x)) c = int("%s%s%s" % (x,x,x)) d = int("%s%s%s%s" % (x,x,x,x)) return a+b+c+d print digit_sum_from_letters(9)
return 11106
But I need to generate a sum for any given integer, so I need a loop, but I'm stuck.
Thanks!
source share