pythonnewbie pythonnewbie - 1 month ago 4
Python Question

Go over all multiples of 3 between 0 and 100 (inclusive), and print the ones that are divisible by 2

What I have so far:

num = range(0, 101, 3)
list = []

if num % 3 == 0:
list.append

print(list)

Answer

I think this is what you are trying to do:

print("\n".join(str(i) for i in range(0, 101, 3) if i % 2 == 0))

or

print([i for i in range(0, 101, 3) if i % 2 == 0])

I am using a list comprehension here.

print(list(range(0, 101, 6)))

does the same thing however.