Comprehending Comprehensions: Need help


Did you create a list called threes_and_fives?

Confused by the error message. Has a list not already been created?

three_and_fives = [x for x in range(1, 16) if (x ** 2) % 3 == 0 or (x ** 2) % 5 == 0]

print three_and_fives


Check the name you have given your list.

Although it makes no difference, I’m a little confused as to why you chose to square x?

Something else of note, due to operator precedence, ** comes before % so the parens are not needed.


Sorry, I was pretty much following the original template given letter by letter, so I forgot to change the x.


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.