Explore key Python math module functions like ceil(), floor(), trunc(), hypot(), and sqrt() in the context of the PCAP-31-03 certification exam. Learn which expressions evaluate to True and why.
Table of Contents
Question
Assuming that the math module has been successfully imported, which of the following expressions evaluate to True? (Choose two.)
A. math.ceil(2.5) == math.trunc(2.5)
B. math.ceil(2.5) < math.floor(2.5)
C. math.floor(2.5) == math.trunc(2.5)
D. math.hypot(3,4) == math.sqrt(25)
Answer
C. math.floor(2.5) == math.trunc(2.5)
D. math.hypot(3,4) == math.sqrt(25)
Explanation
Let’s break down each option to understand why:
A. math.ceil(2.5) == math.trunc(2.5)
This is False. math.ceil(2.5) returns 3, while math.trunc(2.5) returns 2.
- ceil() rounds up to the nearest integer
- trunc() truncates the decimal part, effectively rounding towards zero
B. math.ceil(2.5) < math.floor(2.5)
This is False. math.ceil(2.5) is 3, and math.floor(2.5) is 2.
- ceil() rounds up to 3
- floor() rounds down to 2
3 is not less than 2
C. math.floor(2.5) == math.trunc(2.5)
This is True. Both functions return 2 for the input 2.5.
- floor() rounds down to the nearest integer
- trunc() removes the decimal part
For positive numbers, floor() and trunc() produce the same result
D. math.hypot(3,4) == math.sqrt(25)
This is True. Both expressions evaluate to 5.
- hypot(3,4) calculates the hypotenuse of a right triangle with sides 3 and 4
- sqrt(25) calculates the square root of 25
The hypotenuse of a 3-4-5 right triangle is 5, which is also the square root of 25
In summary, options C and D are the correct choices as they both evaluate to True when using the specified math module functions in Python.
Python Institute PCAP-31-03 certification exam practice question and answer (Q&A) dump with detail explanation and reference available free, helpful to pass the Python Institute PCAP-31-03 exam and earn Python Institute PCAP-31-03 certification.