Introduction to Programming Using Python — Question 17
You are creating a function that manipulates a number. The function has the following requirements:
✑ A float is passed into the function
✑ The function must take the absolute value of the float
✑ Any decimal points after the integer must be removed
Which two math functions should you use? Each correct answer is part of the solution. (Choose two.)
Answer options
- A. math.fmod(x)
- B. math.frexp(x)
- C. math.floor(x)
- D. math.ceil(x)
- E. math.fabs(x)
Correct answer: C, E
Explanation
The correct functions are math.floor(x) and math.fabs(x). math.fabs(x) computes the absolute value of the float, ensuring it is non-negative, while math.floor(x) rounds down to the nearest integer, removing any decimal points. The other options do not fulfill both requirements effectively.