Building lists


#1

Can somebody plizzz tell me what this code does? I do not understand the code inside of the list...

evens_to_50 = [i for i in range(51) if i % 2 == 0]
print( evens_to_50)



Replace this line with your code.


#2

It's looking at every number in the range of 0-50 and if that number can be divided by two with no remainder then it is added to evens_to_50.

The modulo sign (%) outputs the remainder of two that are being divided. For example, 4 / 2 is equal to 2 with a remainder of 0, so 4 % 2 will equal 0. However, 7 / 5 is equal to 1 with a remainder of 2, so 7 % 5 will equal 2.


#3

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