Python Math Inbuilt Functions
In python a number of mathematical operations can be performed with ease by importing a module named “math” which defines various functions which makes our tasks easier.
ceil():
This function returns the smallest integral value greater than the number. If the number is already an integer, the same number is returned.
floor():
This function returns the greatest integral value smaller than the number. If number is already integer, same number is returned.
Example:1
import math print("ceil function") a=2.3 print(math.ceil(a)) a=12.9 print(math.ceil(a)) a=12.23 print(math.ceil(a)) a=62.36 print(math.ceil(a))
Output:
ceil function
3
13
13
63
>>>
Example:2
import math print("floor function") a=23.67 print(math.floor(a)) a=23.17 print(math.floor(a)) a=23.77 print(math.floor(a)) a=23.99 print(math.floor(a))
Output:
floor function
23
23
23
23
>>>
Method:2
Example:3
#Method:2 from math import ceil from math import floor print("ceil function") a=2.3 print(ceil(a)) a=12.9 print(ceil(a)) print("floor function") a=23.67 print(floor(a)) a=23.97 print(floor(a))
Output:
ceil function
3
13
floor function
23
23
>>>
Method:3
Example:4
Method:3 from math import ceil as c from math import floor as f print("ceil function") a=2.3 print(c(a)) a=12.9 print(c(a)) print("floor function") a=23.67 print(f(a)) a=23.97 print(f(a))
Output:
ceil function
3
13
floor function
23
23
>>>
Python String inbuilt Methods Python Math inbuilt Methods Python Date And Time inbuilt Methods Python Random inbuilt Methods