I am currently writing a python code that tries to find out the number of four digit numbers that add up to a specific value. My code is below:
def findSum ():
target = 0;
checkno = 1000;
comboSum = [];
sumArray = [];
while target<=36 :
while checkno<10000 :
digitSum = int(str(checkno)[0]) + int(str(checkno)[1]) + int(str(checkno)[2]) + int(str(checkno)[3]);
if digitSum == target :
comboSum.append(checkno);
checkno = checkno + 1;
sumArray.append(len(comboSum));
target = target + 1;
print (sumArray);
findSum();
However, when I put this through the python interpreter, it returns an array of 36 "0"s. I am not quite sure why this is the case, when I increase the target every time, and then loops back through.
Does anyone know why this is the case?
Thanks!