98-381 Exam QuestionsBrowse all questions from this exam

98-381 Exam - Question 24


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

Show Answer
Correct Answer: CE

To meet the requirements of the function, two math functions can be used: math.fabs() and math.floor(). The math.fabs() function returns the absolute value of a float, which means it removes any negative sign. The math.floor() function takes a float and returns the largest integer less than or equal to the float, effectively removing the decimal points while retaining the integer part. By using these two functions in combination, we can achieve the desired manipulations on the number.

Discussion

4 comments
Sign in to comment
DINESHAJ10
Jun 27, 2020

c&D are correct to get whole number, without decimals

FuzzyDunlop
Jul 7, 2020

If you do ceiling then it will round up which changes the digits to the left of the decimal, whereas option E (floor) will round down so it will remove the digits to the right of the decimal without affecting the digit to the left of the decimal.

nowisthetime
Jul 20, 2020

It said each answer is part of the solution so you would have to combine two answers to form the solution. so C and E is correct.

Mist3
May 16, 2021

math.floor(math.fabs(x)) So the answer is C & E

Neelz
Aug 23, 2020

C & E is right answer. print(math.floor(math.fabs(x)))

sana123
Oct 18, 2020

The math.ceil() method rounds a number UP to the nearest integer, if necessary, and returns the result. To round a number DOWN to the nearest integer, look at the math.floor() method. and c and d

anyadat
Aug 20, 2021

It is asking for the absolute value of the float and to the decimal places to be removed, therefore it will never be math.ceil(). with math.ceil() not just the decimal part will be removed, however the integer shall be rounded up. The correct answers are C & E.