Computer Science

Use a list comprehension to create a list, CB4. The comprehension should consist of the cubes of the numbers 1 through 10 only if the cube is evenly divisible by four. Finally, print that list to the console. Note that in this case, the cubed number should be evenly divisible by 4, not the original number.

Python

Linear Lists

2 Likes

Answer

CB4 = [x**3 for x in range(1, 11) if (x**3) % 4 == 0]
print(CB4)

Output

[8, 64, 216, 512, 1000]

Answered By

3 Likes


Related Questions