Practice mode Python

What is the output of the following Python code? print()

Correct answer B. [1, 9]

Explanation

range(5) yields 0 to 4. The condition x % 2 is truthy only for odd numbers, because the remainder 1 is truthy and 0 is falsy. So only 1 and 3 pass the filter, and their squares give [1, 9]. Taking the even numbers instead gives [0, 4, 16], the common misreading.

Report a problem

Answer checked How we write and check questions

Tip: press A, B, C or D to answer, and N for the next question.

Advertisement

Have a question about this answer?

Your email address will not be published. Required fields are marked *

Links and website addresses are not allowed in comments.