- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

# How to identify and print all the perfect numbers in some closed interval [ 2, n ] using Python?

A perfect number is a positive integer that is equal to the sum of its proper divisors. The smallest perfect number is 6, which is the sum of 1, 2, and 3.

You can find perfect numbers within a given range by testing each number for the given condition in the given range.

## example

def print_perfect_nums(start, end): for i in range(start, end + 1): sum1 = 0 for x in range(1, i): # Check if a divisor, if it is, add to sum if(i % x == 0): sum1 = sum1 + x if (sum1 == i): print(i) print_perfect_nums(1, 300)

## Output

This will give the output

6 28

- Related Questions & Answers
- How to Print all Prime Numbers in an Interval using Python?
- Python program to print all Prime numbers in an Interval
- Python Program to Print Numbers in an Interval
- Print n numbers such that their sum is a perfect square
- Print all numbers less than N with at-most 2 unique digits in C++
- Sum all perfect cube values upto n using JavaScript
- Count numbers upto N which are both perfect square and perfect cube in C++
- Print all n-digit strictly increasing numbers in C++
- Python Program to Read a Number n And Print the Series "1+2+…..+n= "
- Queries to Print All the Divisors of n using C++
- Print all odd numbers and their sum from 1 to n in PL/SQL
- Python program to print all Happy numbers between 1 and 100
- How to print all the Armstrong Numbers from 1 to 1000 using C#?
- Print all prime numbers less than or equal to N in C++
- Python Program to Read a Number n and Print the Natural Numbers Summation Pattern

Advertisements