how to generate a list of 3-digit numbers?
问题 How can I generate a list of 3-digit numbers for which the sum of their digits equal 17? For example assuming number XYZ , we would have X+Y+Z=17 This is how far I got: numbers = list(range(1, 1000)) 回答1: 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. So, take a look at this: result = [x for x in range(100, 1000) if sum(int(y) for y in str(x))==17] print(result)