我目前正在編寫一個python代碼,試圖找出四位數的數字加起來到一個特定的值。我的代碼如下:數字總和代碼 - 返回0的數組
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();
然而,當我把這種通過python解釋,它返回36個「0」的數組。我不太清楚爲什麼會出現這種情況,每當我增加目標,然後循環播放。
有誰知道這是爲什麼?
謝謝!
請不要用分號結束Python中的行。 – poke