Progress

Python ceil() function of the Math module

Python ceil() function of the Math module

Python is very useful when dealing with mathematical operations. Thanks to its math module which contains so many useful functions. The ceil function is one of the most useful functions of the math module in Python.

What is ceil or ceiling function in mathematics?

The general example says that ceil of a number is the smallest integer value not less than that number.

I know that is confusing.

Here is a trick to memorize it and understand better.

Ceil stands for the ceiling which means roof (something above). The ceil returns the nearest greater integer value of a number.

Here are some examples that explain it.

ceil of 3.11 = 4
ceil of 6.89 = 6
ceil of 9.0001 = 10

An interesting example.
ceil of -5.99 = -5 because -5 > -5.99

Now you know the usage of ceil, we can create a Python program to calculate ceil value using math module.

Ceil function of Math module in Python

Here is the general syntax of ceil function in Python.

math.ceil(num)

The ceil function takes one parameter num. We can pass integer or float as an argument.

Here is an example implementation of ceil function.

ceil.py
Copy
import math
#num = int(input("Enter the number to find ceil value: "))

num = 3.11
ceil_value = math.ceil(num)
print(ceil_value)
Output
4

The ceil function in Python is part of the math module.

Return Type of ceil() function

The return of the ceil function is an integer.

Share the Post ;)

Related Posts