{"id":16332,"date":"2021-08-17T08:48:27","date_gmt":"2021-08-17T03:18:27","guid":{"rendered":"https:\/\/python-programs.com\/?p=16332"},"modified":"2021-11-22T18:37:22","modified_gmt":"2021-11-22T13:07:22","slug":"python-program-to-generate-perfect-numbers-in-an-interval","status":"publish","type":"post","link":"https:\/\/python-programs.com\/python-program-to-generate-perfect-numbers-in-an-interval\/","title":{"rendered":"Python Program to Generate Perfect Numbers in an Interval"},"content":{"rendered":"

In the previous article, we have discussed Python Program to Add Two Numbers Without Using the \u201c+\u201d Operator.<\/a>
\nIf the sum of a number\u2019s appropriate divisors (excluding the number itself) equals the number, the number is said to be the perfect number.<\/p>\n

Consider the following example: appropriate divisors of 6 are 1, 2, 3. Because the sum of these divisors equals 6 (1+2+3=6), 6 is considered a perfect number. When we consider another number, such as 12, the proper divisors of 12 are 1, 2, 3, 4, and 6. Now, because the sum of these divisors does not equal 12, 12 is not a perfect number.<\/p>\n

Python programming is simpler and more enjoyable than programming in other languages due to its simplified syntax and superior readability. Now that we understand the concept of a perfect number, let\u2019s construct a Python program to determine whether or not a number is a perfect number. Let\u2019s write some Python code to see if the given user input is a perfect number or not, and have some fun with Python coding.<\/p>\n

Examples:<\/strong><\/p>\n

Example1:<\/strong><\/p>\n

Input:<\/strong><\/p>\n

Given lower limit range = 1\r\nGiven upper limit range=1000<\/pre>\n

Output:<\/strong><\/p>\n

The Perfect numbers in the given range 1 and 1000 are:\r\n1 6 28 496<\/pre>\n

Example 2:<\/strong><\/p>\n

Input:<\/strong><\/p>\n

Given lower limit range = 496\r\nGiven upper limit range=8128<\/pre>\n

Output:<\/strong><\/p>\n

The Perfect numbers in the given range 125 and 8592 are:\r\n496 8128<\/pre>\n

Program to Generate Perfect Numbers in an Interval<\/h2>\n

Below are the ways to generate Perfect Numbers in a given interval.<\/p>\n