• 0 Posts
  • 8 Comments
Joined 1 year ago
cake
Cake day: June 13th, 2023

help-circle






  • It’s because the number variable is a boolean, equal to “is value % 3 zero?”. You’re appending that result to the list for every number.

    What you want is:

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

    The if statement means that you only append to the list if it’s a multiple.