Program to Check if a Number is an Abundant Number in Python
Abundant Number
An abundant number is a number for which the sum of its proper divisors is greater than the number itself. For example, 12 is an abundant number because its divisors (1, 2, 3, 4, 6) sum to 16, which is greater than 12.
We will explore a method to check if a given number is an abundant number using Python programming.
Method: Using a for Loop
We iterate through all numbers less than the given number to find its divisors and sum them up.
def is_abundant(num): sum_divisors = sum(i for i in range(1, num // 2 + 1) if num % i == 0) return sum_divisors > num # Get user input num = int(input("Enter a number: ")) if is_abundant(num): print(f"{num} is an Abundant number") else: print(f"{num} is not an Abundant number")
Output:
Enter a number: 12 12 is an Abundant number