Founding Batch Offer ยท HLD ยท LLD ยท System Design at โ‚น799 until 30 Nov

Abundant Numbers

List abundant numbers from one through one hundred using Python. Students compare proper-divisor totals with their candidates and keep equality from abundance.

AdvancedPhase 6 - Category 1: Number LogicExample 9 of 10
abundant-numbers.py
1# Find abundant numbers
2print("Abundant numbers 1-100:")
3
4for num in range(1, 101):
5 divisor_sum = 0
6 for i in range(1, num):
7 if num % i == 0:
8 divisor_sum += i
9
10 if divisor_sum > num:
11 print(num, end=" ")
12print()

Output

...

The sample abbreviates a longer result. The program prints the intervening values; it does not print these dots.

In this one

  • Build proper-divisor sums
  • Use a strict comparison
  • Separate abundant from perfect

How it works

  1. 1

    Reset divisor_sum for each candidate.

  2. 2

    Add factors below the candidate itself.

  3. 3

    Print only when the completed sum is larger.

Edge cases

Does six print?

Does six print?

No. It is perfect, not abundant.

Does twelve print?

Does twelve print?

Yes. Its proper-divisor sum is sixteen.

What's going on

For each num, the inner loop adds positive factors smaller than num. The completed total must strictly exceed num.

Twelve qualifies because one, two, three, four, and six total sixteen. Six does not, since equality makes it perfect rather than abundant. Resetting the accumulator per candidate prevents earlier divisor sums from affecting later classifications.

Does six print? No. It is perfect, not abundant.

Does twelve print? Yes. Its proper-divisor sum is sixteen.

Quiz

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

Question 1

Which comparison defines abundance?

Pick an answer to check it.

Question 2

Does six print?

Pick an answer to check it.

Questions people ask

Does six print?

No. It is perfect, not abundant.

Does twelve print?

Yes. Its proper-divisor sum is sixteen.

Which comparison defines abundance?

divisor_sum > num.