Q. 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.


Answer :-

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

Output :-

[2, 4, 6, 8, 10]

>>>

Credit :- Jinsu

3 Comments

You can help us by Clicking on ads. ^_^
Please do not send spam comment : )

  1. #Correct Answer:
    CB4 = [i for i in range (1,11) if (i ** 3) % 4 == 0 ]
    print(CB4)

    ReplyDelete
    Replies
    1. Thanks for giving credit to me and updating the answer.

      Delete

Post a Comment

You can help us by Clicking on ads. ^_^
Please do not send spam comment : )

Previous Post Next Post