Welcome to collectivesolver - Programming & Software Q&A with code examples. A website with trusted programming answers. All programs are tested and work.

Contact: aviboots(AT)netvision.net.il

Buy a domain name - Register cheap domain names from $0.99 - Namecheap

Scalable Hosting That Grows With You

Secure & Reliable Web Hosting, Free Domain, Free SSL, 1-Click WordPress Install, Expert 24/7 Support

Semrush - keyword research tool

Boost your online presence with premium web hosting and servers

Disclosure: My content contains affiliate links.

39,959 questions

51,901 answers

573 users

How to check whether a number is perfect or not in Python

1 Answer

0 votes
# If the sum of all factors of a number is equal to the number, then the number is perfect

def is_perfect_number(num):
    # 28
    # factors = 1 + 2 + 4 + 7 + 14
    # 1 + 2 + 4 + 7 + 14 = 28

    sum_of_factors = 0

    for i in range(1, num):
        if num % i == 0:
            sum_of_factors += i

    return sum_of_factors == num

num = 28
if is_perfect_number(num):
    print("Perfect Number")
else:
    print("Not a Perfect Number")



'''
run:
 
Perfect Number
 
'''

 



answered Feb 27, 2016 by avibootz
edited Nov 7, 2025 by avibootz

Related questions

1 answer 105 views
1 answer 112 views
1 answer 107 views
1 answer 99 views
...