{"id":24067,"date":"2021-10-14T09:12:47","date_gmt":"2021-10-14T03:42:47","guid":{"rendered":"https:\/\/python-programs.com\/?p=24067"},"modified":"2021-11-05T20:56:43","modified_gmt":"2021-11-05T15:26:43","slug":"python-program-for-ceil-function","status":"publish","type":"post","link":"https:\/\/python-programs.com\/python-program-for-ceil-function\/","title":{"rendered":"Python Program for ceil() Function"},"content":{"rendered":"
In the previous article, we have discussed Python Program for Set discard() Method<\/a> If necessary, the math.ceil() method rounds a number UP<\/strong> to the nearest integer and returns the result.<\/p>\n The ceil function in Python is used to return the smallest integer value that is greater than or equal to the specified expression or number.<\/p>\n Syntax:<\/strong><\/p>\n Parameter Values:<\/strong><\/p>\n number: This is required. It Sets the number to round up.<\/p>\n Note:<\/strong> The ceil function returns the ceiling value if the number argument is positive or negative. Return Value: <\/strong>The return value is an int value that represents the rounded number.<\/p>\n Examples:<\/strong><\/p>\n Example1:<\/strong><\/p>\n Input:<\/strong><\/p>\n Output:<\/strong><\/p>\n Example2:<\/strong><\/p>\n Input:<\/strong><\/p>\n Output:<\/strong><\/p>\n Approach:<\/strong><\/p>\n Below is the implementation:<\/strong><\/p>\n Output:<\/strong><\/p>\n Approach:<\/strong><\/p>\n Below is the implementation:<\/strong><\/p>\n Output:<\/strong><\/p>\n Read all the mathematical functions available in Python and understand how to implement them in your program by using the tutorial of Python Mathematical Methods Examples<\/a>.<\/p>\n In the previous article, we have discussed Python Program for Set discard() Method ceil() Function in Python: If necessary, the math.ceil() method rounds a number UP to the nearest integer and returns the result. The ceil function in Python is used to return the smallest integer value that is greater than or equal to the …<\/p>\n
\nceil() Function in Python:<\/strong><\/p>\nmath.ceil(number)<\/pre>\n
\nThe math ceil function returns TypeError if the number argument is not a number.<\/p>\nGiven tuple = (1.3, 10.04, -4.4, 7.7, 9.45)\r\nGiven List = [2.8, 3.4, -1.7, -6.82, 12.2]<\/pre>\n
Given positive number 9.2 ceiling value = 10.00\r\nGiven negative number -8.6 ceiling value = -8.00\r\nGiven Tuple element(gvn_tupl[3]) ceiling value = 8.00\r\nGiven Tuple element(gvn_lst[2]) ceiling value = -1.00\r\nThe Ceil of pi is: 4\r\nGiven multiple number(35+40-10.3) ceiling value = 65.00<\/pre>\n
Given tuple = (2.4, 85.67, 37.8, -25.5)\r\nGiven List = [45.9, 11.32, -25, 6, 12.8, -10]<\/pre>\n
Given positive number 30.1 ceiling value = 31.00\r\nGiven negative number -20.4 ceiling value = -20.00\r\nGiven Tuple element(gvn_tupl[0]) ceiling value = 3.00\r\nGiven Tuple element(gvn_lst[3]) ceiling value = 6.00\r\nThe Ceil of pi is: 4\r\nGiven multiple number (23-10+5) ceiling value = 18.00<\/pre>\n
Program for ceil() Function in Python<\/h2>\n
\n
Method #1: Using Built-in Functions (Static Input)<\/h3>\n
\n
# Import math module using the import keyword.\r\nimport math\r\n# Give the tuple as static input and store it in a variable.\r\ngvn_tupl = (1.3, 10.04, -4.4, 7.7, 9.45)\r\n# Give the list as static input and store it in another variable.\r\ngvn_lst = [2.8, 3.4, -1.7, -6.82, 12.2]\r\n# Apply math. ceil() function to any positive number and print it.\r\nprint('Given positive number 9.2 ceiling value = %.2f' % math.ceil(9.2))\r\n# Apply math. ceil() function to any negative number and print it.\r\nprint('Given negative number -8.6 ceiling value = %.2f' % math.ceil(-8.6))\r\n# Apply math. ceil() function to the given tuple element\u00a0and print it.\r\nprint('Given Tuple element(gvn_tupl[3]) ceiling value = %.2f' % math.ceil(\r\n gvn_tupl[3]))\r\n# Apply math. ceil() function to the given list element\u00a0and print it.\r\nprint(\r\n 'Given Tuple element(gvn_lst[2]) ceiling value = %.2f' % math.ceil(gvn_lst[2]))\r\n# Apply math. ceil() function to the pi value and print it.\r\nprint(\"The Ceil of pi is: \", math.ceil(math.pi))\r\n# Apply math. ceil() function to any multiple numbers and print it.\r\nprint('Given multiple number(35+40-10.3) ceiling value = %.2f' %\r\n math.ceil(35+40-10.3))\r\n<\/pre>\n
Given positive number 9.2 ceiling value = 10.00\r\nGiven negative number -8.6 ceiling value = -8.00\r\nGiven Tuple element(gvn_tupl[3]) ceiling value = 8.00\r\nGiven Tuple element(gvn_lst[2]) ceiling value = -1.00\r\nThe Ceil of pi is: 4\r\nGiven multiple number(35+40-10.3) ceiling value = 65.00<\/pre>\n
Method #2: Using Built-in Functions (User Input)<\/h3>\n
\n
# Import math module using the import keyword.\r\nimport math\r\n# Give the tuple as user input using list(),map(),input(),and split() functions.\r\n# Store it in a variable.\r\ngvn_tupl = tuple(map(float, input(\r\n 'Enter some random tuple Elements separated by spaces = ').split()))\r\n# Give the list as user input using list(),map(),input(),and split() functions.\r\n# Store it in another variable.\r\ngvn_lst = list(map(float, input(\r\n 'Enter some random List Elements separated by spaces = ').split()))\r\n# Give the positive number as user input using the float(input()) function and\r\n# Store it in another variable.\r\ngvn_positvenum=float(input(\"Enter some random number = \"))\r\n# Apply math. ceil() function to the given positive number and print it.\r\nprint('Given positive number',gvn_positvenum,'ceiling value = %.2f' % math.ceil(gvn_positvenum))\r\n# # Give the negative number as user input using the float(input()) function and\r\n# Store it in another variable.\r\ngvn_negatvenum=float(input(\"Enter some random number = \"))\r\n# Apply math. ceil() function to the given negative number and print it.\r\nprint('Given negative number',gvn_negatvenum,'ceiling value = %.2f' % math.ceil(gvn_negatvenum))\r\n# Apply math. ceil() function to the given tuple element\u00a0and print it.\r\nprint('Given Tuple element(gvn_tupl[0]) ceiling value = %.2f' % math.ceil(\r\n gvn_tupl[0]))\r\n# Apply math. ceil() function to the given list element\u00a0and print it.\r\nprint(\r\n 'Given Tuple element(gvn_lst[3]) ceiling value = %.2f' % math.ceil(gvn_lst[3]))\r\n\r\n\r\n\r\n<\/pre>\n
Enter some random tuple Elements separated by spaces = 12.3 -11.2 6.7 4.6\r\nEnter some random List Elements separated by spaces = 8.5 10.3 -6.4 -20.8\r\nEnter some random number = 30.1\r\nGiven positive number 30.1 ceiling value = 31.00\r\nEnter some random number = -20.4\r\nGiven negative number -20.4 ceiling value = -20.00\r\nGiven Tuple element(gvn_tupl[0]) ceiling value = 13.00\r\nGiven Tuple element(gvn_lst[3]) ceiling value = -20.00<\/pre>\n
\n