找出小于100点能够被3整除的正整数。

方法一:

a = []              
for n in range(1,100)
    if n % 3 == 0:  
        a.append(n) 
print(a)            

输出结果为:[3, 6, 9, 12, 15, 18, 21, 24, 27, 30, 33, 36, 39, 42, 45, 48, 51, 54, 57, 60, 63, 66, 69, 72, 75, 78, 81, 84, 87, 90, 93, 96, 99]


方法二:

a = list(range(3,100,3))
print(a)    

输出结果为:

[3, 6, 9, 12, 15, 18, 21, 24, 27, 30, 33, 36, 39, 42, 45, 48, 51, 54, 57, 60, 63, 66, 69, 72, 75, 78, 81, 84, 87, 90, 93, 96, 99]

上一篇:leetcode 69 求平方根


下一篇:Leetcode 69. x 的平方根