如何获取该数字中各个数字之和为13且最后一位数字为5的4位数字的所有可能组合的列表

I_m*_*que -2 python python-3.x

如何求出该数字中每个数字和为13、最后一位数字为5的所有可能的组合?

我正在 python 中尝试如下:

nmz = []
for i in range(1000,10000):
    if ((sum(int(j) for j in str(i))==13) & (i % 10)):
        nmz = nmz.append(i)
        return(nmz)
    else:
        continue
Run Code Online (Sandbox Code Playgroud)

我收到错误并且无法获得预期的输出:

nmz = [1165,    1345,   1435,   1615,   1705,   2245,   2425,   3055 ..... ]
Run Code Online (Sandbox Code Playgroud)

错误是:

  1. 没有预期的输出
  2. 语法错误:“返回”外部函数

Ctr*_*rlZ 7

从 1000 开始范围是没有意义的,因为它不满足数字应以 5 结尾的重要标准。因此,从 1005 开始并增加 10。因此:

mylist = []
for i in range(1_005, 10_000, 10):
    if sum(int(d) for d in str(i)) == 13:
        mylist.append(i)

print(mylist)
Run Code Online (Sandbox Code Playgroud)

输出:

[1075, 1165, 1255, 1345, 1435, 1525, 1615, 1705, 2065, 2155, 2245, 2335, 2425, 2515, 2605, 3055, 3145, 3235, 3325, 3415, 3505, 4045, 4135, 4225, 4315, 4405, 5035, 5125, 5215, 5305, 6025, 6115, 6205, 7015, 7105, 8005]
Run Code Online (Sandbox Code Playgroud)