且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何生成3位数字的列表?

更新时间:2023-02-10 14:54:04

您似乎希望数字的总和为17,而不是数字的总和. >作为但我希望第一个数字+第二个数字+第三个数字= 17?" 表示.

It appears that you want the sum of the digits to be 17 and not the sum of the numbers as the "but I want the first number + the second number + the third number = 17 ?" implies.

所以,看看这个:

result = [x for x in range(100, 1000) if sum(int(y) for y in str(x))==17]
print(result)  # [179, 188, 197, 269, ..., 962, 971, 980]