PrepAway - Latest Free Exam Questions & Answers

Which two math functions should you use?

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.)

A. math.fmod(x)
B. math.frexp(x)

C. math.floor(x)

D. math.ceil(x)

E. math.fabs(x)

Explanation:
C: math.floor(x) returns the largest integer less than or equal to x.
E: math.fabs(x) returns the absolute value of x.

Incorrect Answers:
A: math.fmod() takes two variables
B: math.frexp(x) returns the mantissa and exponent of x as the pair (m, e). m is a float and e is an integer
D: math.ceil(x) returns the smallest integer greater than or equal to x

References: https://docs.python.org/2/library/math.html#number-theoretic-and-representation-functionshttps://docs.python.org/3/library/math.html


Leave a Reply