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

Abundant Number Check

Find whether proper divisors sum to more than a positive integer. Students use a factor loop to distinguish abundant numbers from perfect and deficient ones.

IntermediatePhase 2 - Level 2: Number-based Looping LogicExample 14 of 14
abundant-number-check.py
1# Take number
2num = int(input("Enter a number: "))
3
4# Find sum of proper divisors
5divisor_sum = 0
6for i in range(1, num):
7 if num % i == 0:
8 divisor_sum += i
9
10# Check abundant
11if num > 0 and divisor_sum > num:
12 print("Abundant number")
13else:
14 print("Not an abundant number")

Output

Enter a number: 12
Abundant number

In this one

  • Compare proper-divisor totals
  • Recognize strict abundance
  • Exclude negative inputs

How it works

  1. 1

    Sum factors smaller than num.

  2. 2

    Require num positive and the sum strictly greater.

  3. 3

    Print the abundant or not-abundant result.

Edge cases

Is six abundant?

Is six abundant?

No. Equality is not enough.

Should negative numbers pass?

Should negative numbers pass?

No. The final test must require a positive input as well as a larger divisor sum.

What's going on

An abundant number has a proper-divisor sum strictly greater than itself. The loop scans positive integers below num and adds those that divide it exactly.

For twelve, factors one, two, three, four, and six total sixteen, so it passes. Six is perfect instead: its total equals six, which is not greater. This definition applies to positive integers, not negative inputs that can otherwise pass an empty-sum comparison.

Is six abundant? No. Equality is not enough.

Should negative numbers pass? No. The final test must require a positive input as well as a larger divisor sum.

Quiz

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

Question 1

Which input is abundant?

Pick an answer to check it.

Question 2

Is six abundant?

Pick an answer to check it.

Questions people ask

Is six abundant?

No. Equality is not enough.

Should negative numbers pass?

No. The final test must require a positive input as well as a larger divisor sum.

Which input is abundant?

12.