So I’m trying to make a list of numbers that are multiples of 3, this is my code:

multiples_of_3 = []
for value in range(3, 31):
    number = value % 3 == 0
    multiples_of_3.append(number)

print(multiples_of_3)

But it transforms the results into booleans, which throws me a list with false and trues instead of numbers, what I’m doing wrong? I know comprehension lists exist and that this could be done more efficiently but well, I’m trying to learn and writing it as a comprehension list doesn’t make it easier.

  • Soviet SnakeOP
    link
    31 year ago

    I thought of using an if, but I’m reading a book called “Python Crash Course” and he hasn’t gone over if statements yet, so I thought there has to be a way to express it only using for statements. I have some more knowledge than what was already presented to me in the book from college, but I’m trying to follow the book’s reasoning so far.