{"id":24143,"date":"2021-10-14T08:32:47","date_gmt":"2021-10-14T03:02:47","guid":{"rendered":"https:\/\/python-programs.com\/?p=24143"},"modified":"2021-11-05T20:54:05","modified_gmt":"2021-11-05T15:24:05","slug":"python-program-for-isfinite-function","status":"publish","type":"post","link":"https:\/\/python-programs.com\/python-program-for-isfinite-function\/","title":{"rendered":"Python Program for isfinite() Function"},"content":{"rendered":"
In the previous article, we have discussed Python Program for fsum() Function<\/a> The math.isfinite() method determines whether or not a number is finite.<\/p>\n If the specified number is a finite number, this method returns true; otherwise, it returns False.<\/p>\n Syntax:<\/strong><\/p>\n Parameters:<\/strong><\/p>\n Value:<\/strong> This is required. The value to be checked. A number (float\/integer\/infinite\/NaN\/finite) must be specified.<\/p>\n Return Value: <\/strong>It returns a boolean value. Returns True if x is finite and False if x is infinity or NaN.<\/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 <\/p>\n","protected":false},"excerpt":{"rendered":" In the previous article, we have discussed Python Program for fsum() Function isfinite() Function in Python: The math.isfinite() method determines whether or not a number is finite. If the specified number is a finite number, this method returns true; otherwise, it returns False. Syntax: math.isfinite(value) Parameters: Value: This is required. The value to be checked. …<\/p>\n
\nisfinite() Function in Python:<\/strong><\/p>\nmath.isfinite(value)<\/pre>\n
Given Number = 20\r\nGiven number = -100\r\nGiven Number = math.pi\r\nGiven value = NaN\r\nGiven value = inf<\/pre>\n
Checking if the above given number 20 is finite or not : True\r\nTrue\r\nTrue\r\nFalse\r\nFalse<\/pre>\n
Given Number = 10000\r\nGiven value = -math.inf\r\nGiven value = nan<\/pre>\n
Checking if the above given number 10000 is finite or not : True\r\nFalse\r\nFalse<\/pre>\n
Program for isfinite() 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 number as static input and store it in a variable.\r\ngvn_numb = 20\r\n# Apply math.isfinite() function to the given number to check if the given number\r\n# is finite or not.\r\n# Store it in another variable.\r\nrslt = math.isfinite(gvn_numb)\r\n# print the above result.\r\nprint(\"Checking if the above given number\",\r\n gvn_numb, \"is finite or not :\", rslt)\r\n# similarly check for the other values\u00a0\r\nprint(math.isfinite(-100))\r\nprint(math.isfinite(math.pi))\r\nprint(math.isfinite(float('NaN')))\r\nprint(math.isfinite(float('inf')))\r\n<\/pre>\n
Checking if the above given number 20 is finite or not : True\r\nTrue\r\nTrue\r\nFalse\r\nFalse<\/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 number as user input using the int(input()) function and store it in a variable.\r\ngvn_numb = int(input('Enter some random number = '))\r\n# Apply math.isfinite() function to the given number to check if the given number\r\n# is finite or not.\r\n# Store it in another variable.\r\nrslt = math.isfinite(gvn_numb)\r\n# print the above result.\r\nprint(\"Checking if the above given number\",\r\n gvn_numb, \"is finite or not :\", rslt)\r\n# similarly check for the other numbers\r\nb = int(input('Enter some random number = '))\r\nprint(math.isfinite(b))<\/pre>\n
Enter some random number = -1000\r\nChecking if the above given number -1000 is finite or not : True\r\nEnter some random number = -19999\r\nTrue<\/pre>\n
\n