Founding Batch Offer · HLD · LLD · System Design at ₹799 until 30 Nov

Check Abundant Number in Python

12 has proper divisors totaling 16. Follow this Python beginner search to understand abundant numbers and why an equal divisor sum belongs to another category.

BeginnerConditional ProgramsExample 13 of 20
check-abundant-number.py
1# Program to check abundant number
2
3num = int(input("Enter a positive integer: "))
4
5if num <= 0:
6 print("Number must be positive.")
7else:
8 total = 0
9 for i in range(1, num):
10 if num % i == 0:
11 total += i
12
13 if total > num:
14 print(num, "is an abundant number")
15 else:
16 print(num, "is not an abundant number")

Output

12 is an abundant number

The proper divisors total 16, so the greater-than comparison succeeds for 12.

In this one

  • Sum proper divisors
  • Distinguish greater-than from equality
  • Classify abundant versus non-abundant values

How it works

  1. 1

    Read num and reject non-positive values.

  2. 2

    Loop below num, adding candidates with zero remainder.

  3. 3

    Compare total > num after the loop completes.

Edge cases

Perfect number

Enter 6.

Its proper divisor sum is 6, so it is not abundant.

One

Enter 1.

The empty divisor range leaves total zero, which is not greater than 1.

What's going on

12 has proper divisors 1, 2, 3, 4, and 6. They total 16, which is more than 12. That excess makes it abundant.

The loop uses range(1, num), so num itself is excluded. Each candidate that leaves remainder zero contributes to total. Only after all candidates are checked does total > num decide the result.

A perfect number such as 6 has an equal divisor sum and therefore fails this greater-than test. A deficient number has a smaller sum and fails too. The code groups both under not abundant. It rejects non-positive inputs before doing the divisor search, which otherwise grows linearly with the input size.

After this program

If the idea is still fuzzy, read Day 8: Conditional Statements in the Python course. For a short check, try the Python quiz (300 questions). Stay with all 20 conditional programs, or see every topic on Python exercises.

Quiz

Tap an option. The answer stays hidden until you pick.

Question 1

Why is 12 abundant?

Pick an answer to check it.

Question 2

Does equality pass this test?

Pick an answer to check it.

Questions people ask

Why is 12 abundant?

Its proper divisors total 16, which is greater than 12.

Does equality pass this test?

No. Equality describes a perfect number; abundance requires a larger sum.

Is num itself included in the sum?

No. The exclusive endpoint of range leaves out the number itself.