Practice mode Python

What is the output of the following Python code? import math; print(math.floor(-2.5), math.ceil(-2.5))

Correct answer A. -3 -2

Explanation

math.floor() returns the largest integer less than or equal to x, and for -2.5 that is -3, because -3 lies below -2.5 on the number line. math.ceil() returns the smallest integer greater than or equal to x, which is -2. Thinking of floor as dropping the decimal part gives the wrong answer for negatives.

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.