0% found this document useful (0 votes)
2 views1 page

Jai 2

The document provides a Python program that checks if a given number is a perfect number. A perfect number is defined as a positive integer equal to the sum of its positive divisors, excluding itself. Examples include 28 and 496 as perfect numbers, while 27 and 890 are not.

Uploaded by

nopeynope0
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views1 page

Jai 2

The document provides a Python program that checks if a given number is a perfect number. A perfect number is defined as a positive integer equal to the sum of its positive divisors, excluding itself. Examples include 28 and 496 as perfect numbers, while 27 and 890 are not.

Uploaded by

nopeynope0
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 1

Write a python program getting input of a number and finding out its a perfect

number or not
A perfect number is a positive integer number in which sum of all positive
divisors excluding the number itself is equal to that number.
Perfect Number Examples, 28 is perfect number since its divisors are 1, 2, 4, 7
and 14. Sum of divisors is: 1+2+4+7+14=28

For example:
Input Result
28 perfect number
27 not a perfect number
496 perfect number
890 not a perfect number

Answer:

# Get input from the user


number = int(input("Enter a number: "))

# Initialize sum of divisors


sum_of_divisors = 0

# Iterate through possible divisors from 1 to number-1


for i in range(1, number):
if number % i == 0:
sum_of_divisors += i

# Check if the sum of divisors equals the original number


if sum_of_divisors == number:
print(number, "is a perfect number.")
else:
print(number, "is not a perfect number.")

You might also like