tags:

views:

226

answers:

4

I am not sure, whether I should use for -loop. Perhaps, like

for i in range(145): 
  by 6:    //mistake here?
  print i
+4  A: 

I would prefer:

for i in xrange(25):    # from 0 to 24
    print 6*i

You can easily build a list containing the same numbers with a similar construct named list comprehension:

numbers = [6*i for i in xrange(25)]
print numbers

If you already have a list of (unknown) numbers, say someNumbers, but you want to print only those which are multiples of 6:

for i in someNumbers:
    if i%6 == 0:
        print i
Federico Ramponi
+19  A: 
for i in range(0,150,6):
     print i

if you are stepping by a constant

Nikron
This is better to read than Ramponi's answer, in my opinion. Premature optimization is the root of all evil.
strager
Oh, damn it. You know, the fastest gun in the west thing :) +1
Federico Ramponi
A: 
i = 1

while i * 6 < 144:
    i = i + 1
    print i * 6

There are plenty of ways to do this

Logan Serman
A: 

reqlist = [i for i in range(0,150,6)]

Senthil Kumaran