Find a number, which is smaller than a given number, and has the same amounts of digit as it, and the sum of digits is the same.
N = int(input())
sume = 0
lik = [int(x) for x in str(N)]
for k in range(len(lik)):
sume += lik[k]
def get_sum(N):
global sumd
sumd = 0
lis = [int(x) for x in str(N)]
for k in range(len(lis)):
sumd += lis[k]
return sumd
cnt = 0
for i in range(N-1, 10**(len(str(N))-1)-1, -1):
get_sum(i)
if sumd == sume:
print(i)
break
else:
cnt += 1
if cnt == N - 10**(len(str(N))-1):
print(0)
And it's perfectly fine, except that it cannot run big inputs, well, the requirement is number which has 15 DIGITS, and mine can do maximum 7 digits, how do I fix this? I guess that I have to replace loops, as it can't take big ones, but also the case which contain zeros.