python - Multiples of 3 and 5 -


i trying write program takes input number t(number of test cases), , asks numbers n.

this code:

t = int(raw_input()) l = [int(raw_input()) in range(t)] l1 = [] in range(0,l[i]):     if (i%3 == 0 or i%5 ==0):         l1.append(i) print l1 

input: 2 10 20

output: [0, 3, 5, 6, 9, 10, 12, 15, 18]

i output of following format:

[[0, 3, 5, 6, 9], [0, 3, 5, 6, 9, 10, 12, 15, 18]]

here [0, 3, 5, 6, 9] list has elements both multiples of 3 , 5 number 10

[0, 3, 5, 6, 9, 10, 12, 15, 18] list has elements both multiples of 3 , 5 number 20

i new python. kindly let me know how should proceed on this.

the following produce list of lists containing multiples of 3 , 5 less given number.

l = [10,20] l1 = [] in l:     l2 = [] # initialize new list     j in range(i):         if not (j%3 , j%5): # use falsy values , demorgan's law             l2.append(j) # append list     if l2: # use if don't want keep empty lists         l1.append(l2) 

>>> l1 [[0, 3, 5, 6, 9], [0, 3, 5, 6, 9, 10, 12, 15, 18]] 

Comments