Check Abundant Number in Python

Check whether a number is abundant (sum of proper divisors is greater than the number).

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

Enter a positive integer: 12
12 is an abundant number

What's going on

An abundant number has sum of proper divisors greater than the number itself.

We reuse the divisor-summing pattern and compare with num.

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.