Hello, guys! I would like to hear your opinion about the solution for this task I am struggling to make. I am sure that is not the easiest way what I am trying to do, but I would love to accomplish this task using mathematics (I remember similar task when I was in High School, however now I can't do that same way).
So, basically what I am trying to achieve is to represent an integer in the following shape:
sum=0 n_len=len(str(n)) i=n_len while i<=(n_len) and i!=1: digit=n//(10**(i-1)) #Here is I can't really figure out the next iteration... #Maybe it's better to use exponent here return n, sum i-=1 if i==1: sum+=n % (10**(i-1)) return sum print digit_sum(434)
Please, I am sure you guys know the solution. I won't be able to sleep unless I find the way