019. What is the output of the 2 points
following program? from math
import* a = 2.13 b = 3.7777 c =
-3.12 print(int(a), floor(b).
ceil(c), fabs(c))
O a) 23-43
Ob) 23-33.12
Oc)24-33
O d) 2 3 -43.12
Answers
Answer:
Option B
2 3 -3 3.12
Note: Check the attachment given below to see the compiled code. Software used : Python Shell (3.7.0 version).
Program:
from math import *
a = 2.13
b = 3.7777
c = -3.12
print(int(a), floor(b),ceil(c), fabs(c))
Output:
2 3 -3 3.12
Explanation:
from math import * : It imports all the built-in math functions from math library.
int(a) : int() is a function that changes the type of the parameter passed into an integer.
Example:
a=2.13 : It is a float number. On passing this variable into int(), float converts into int.
as in, int(a) gives 2 as output.
Similarly, int(3.986) gives 3 as output.
floor(b) : floor() deals with converting a float value into it's nearest less integer value.
Example:
b=3.7777 : It is a float value. It's nearest less integer value is 3. So, floor(b) results 3.
Similarly, floor(-9.876) gives -10 as output (least neares integer).
ceil(c) : It is opposite to floor(). ceil() deals with converting a float value into it's nearest maximum integer value.
Example:
c= -3.12 : It is a float value. It's nearest maximum integer value is -3. So, ceil(c) results -3.
Similarly, ceil(19.876) gives 20 as output.
fabs(c) : fabs() deals with presenting the absolute value of a given float number. Note that absolutes are always positive.
Example:
c= -3.12 : It is a float value. As the absolute results positive number, fabs(-3.12) results 3.12 as output.
Similarly, fabs(9.87) gives 9.87 itself as output.
Hope it helps. If yes, leave a smile :)