{"id":18579,"date":"2021-08-26T10:38:15","date_gmt":"2021-08-26T05:08:15","guid":{"rendered":"https:\/\/python-programs.com\/?p=18579"},"modified":"2021-11-22T18:37:18","modified_gmt":"2021-11-22T13:07:18","slug":"python-program-to-check-abundant-number-or-not","status":"publish","type":"post","link":"https:\/\/python-programs.com\/python-program-to-check-abundant-number-or-not\/","title":{"rendered":"Python Program to Check Abundant Number or Not"},"content":{"rendered":"
In the previous article, we have discussed Python Program to Reverse the Order of Palindrome Words in a Sentence<\/a> An abundant number is one in which the sum of the number’s proper divisors is greater than the number itself.<\/p>\n To check for an Abundant number, find and add the number’s proper divisors, then compare the sum to the number; if the sum is greater than the number, the number is an Abundant number; otherwise, the number is not an Abundant number. The difference between the sum and the number is referred to as abundant.<\/p>\n For example :<\/p>\n Let Number = 18<\/p>\n The proper divisors are:<\/p>\n 1*18<\/p>\n 6*3<\/p>\n 9*2<\/p>\n The sum=1+6+9+3+2= 21 >18<\/p>\n Therefore 18 is an Abundant Number.<\/p>\n Some of the examples of Abundant Numbers are:<\/p>\n 12, 18, 20, 24, 30, 36, 40, 42, 48, 54, 56, 60, 66…..and so on.<\/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 Below are the ways to check whether the given number is an Abundant Number or not in Python<\/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 Explore more instances related to python concepts from\u00a0Python Programming Examples<\/a>\u00a0Guide and get promoted from beginner to professional programmer level in Python Programming Language.<\/p>\n In the previous article, we have discussed Python Program to Reverse the Order of Palindrome Words in a Sentence Abundant Number: An abundant number is one in which the sum of the number’s proper divisors is greater than the number itself. To check for an Abundant number, find and add the number’s proper divisors, then …<\/p>\n
\nAbundant Number:<\/strong><\/p>\nGiven Number = 24<\/pre>\n
The given Number { 24 } is an Abundant Number<\/pre>\n
Given Number = 25<\/pre>\n
The given Number { 25 } is Not an Abundant Number<\/pre>\n
Program to Check Abundant Number or Not in Python<\/h2>\n
\n
Method #1: Using For Loop (Static Input)<\/h3>\n
\n
# Give the number as static input and store it in a variable.\r\ngvn_numb = 24\r\n# Take a variable say \"divisrs_sum\" and initialize it with 1.\r\ndivisrs_sum = 1\r\n# Iterate from 2 to the given number using the for loop.\r\nfor itr in range(2, gvn_numb):\r\n # Check if the given number modulus iterator value is equal to 0 or not using the\r\n # if conditional statement.\r\n if(gvn_numb % itr == 0):\r\n # If the statement is true, then add the iterator with the sum of divisors \"divisrs_sum\"\r\n # and store it in the same variable \"divisrs_sum\".\r\n divisrs_sum = divisrs_sum + itr\r\n# Check if the sum of divisors (divisrs_sum) is greater than the given number using the\r\n# if conditional statement.\r\nif(divisrs_sum > gvn_numb):\r\n # If the statement is true, then print \"The given Number is an Abundant Number\".\r\n print(\"The given Number {\", gvn_numb, \"} is an Abundant Number\")\r\nelse:\r\n # If it is false, then print \"The given Number is Not an Abundant Number\".\r\n print(\"The given Number {\", gvn_numb, \"} is Not an Abundant Number\")\r\n<\/pre>\n
The given Number { 24 } is an Abundant Number<\/pre>\n
Method #2: Using For loop (User Input)<\/h3>\n
\n
# Give the number as user input using the int(input()) function and\r\n# store it in a variable.\r\ngvn_numb = int(input(\"Enter some random Number = \"))\r\n# Take a variable say \"divisrs_sum\" and initialize it with 1.\r\ndivisrs_sum = 1\r\n# Iterate from 2 to the given number using the for loop.\r\nfor itr in range(2, gvn_numb):\r\n # Check if the given number modulus iterator value is equal to 0 or not using the\r\n # if conditional statement.\r\n if(gvn_numb % itr == 0):\r\n # If the statement is true, then add the iterator with the sum of divisors \"divisrs_sum\"\r\n # and store it in the same variable \"divisrs_sum\".\r\n divisrs_sum = divisrs_sum + itr\r\n# Check if the sum of divisors (divisrs_sum) is greater than the given number using the\r\n# if conditional statement.\r\nif(divisrs_sum > gvn_numb):\r\n # If the statement is true, then print \"The given Number is an Abundant Number\".\r\n print(\"The given Number {\", gvn_numb, \"} is an Abundant Number\")\r\nelse:\r\n # If it is false, then print \"The given Number is Not an Abundant Number\".\r\n print(\"The given Number {\", gvn_numb, \"} is Not an Abundant Number\")\r\n<\/pre>\n
Enter some random Number = 48\r\nThe given Number { 48 } is an Abundant Number<\/pre>\n
\n