Identify the correct output of the following Python program segment: import…
2023
Identify the correct output of the following Python program segment: import math print(math.fabs(-10))
- A.
1
- B.
-10
- C.
-10.0
- D.
10.0
Attempted by 1554 students.
Show answer & explanation
Correct answer: D
Answer: 10.0
Explanation:
The math.fabs() function returns the absolute value of a number as a float. For the input -10, the absolute value is 10, but it is returned as a floating-point number, so the result is 10.0.
When print() is used, it displays the float value exactly as 10.0, including the decimal point. This is why the output is 10.0, not 10 or any negative value.
Why the provided choices are incorrect:
The text '1 / 1' is unrelated to the program output.
Any choice showing -10 or -10.0 is wrong because the absolute value is non-negative; the sign should be positive.
A choice showing integer 10 is incomplete: math.fabs returns a float, so the printed result is 10.0 (with a decimal point).