john727377 wrote:I need some help in counting the number of abundant and deficient numbers below is the code for the perfect number for a limit.I also want to count both abundant and deficient numbers.So could anyone please help in the code.

- Code: Select all
`limit = int(input("enter upper limit for perfect number search: "))`

for n in range(2, limit + 1):

sum = 0

abd = 0

defc = 0

for divisor in range(1, n):

if not n % divisor:

sum += divisor

if sum == n:

print(n, "is a perfect number")

if sum > n :

abd+=1

if sum < n:

defc+=1

print("the abundant are" ,abd)

print("the deficient are",defc)

Just hints this time...

Look carefully at where

abd and

defc are defined. How often are they initialized to 0?

Check your indentation. When are

abd and

defc incremented? Indentation is important.

Use more descriptive variable names.

Use space around operators.

adb += 1 is easier to read.

casevh