## abundant and deficient number counting

This is the place for queries that don't fit in any of the other categories.

### abundant and deficient number counting

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+=1print("the abundant are" ,abd)print("the deficient are",defc)`
john727377

Posts: 4
Joined: Tue Feb 04, 2014 3:42 am

### Re: abundant and deficient number counting

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+=1print("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.

casevh
casevh

Posts: 114
Joined: Sat Feb 09, 2013 7:35 am

### Re: abundant and deficient number counting

Got the solution here is the code:

Code: Select all
`limit=int(input("enter number"))counter1=0counter2=0counter3=0for n in range(2, limit + 1):    sum = 0    for divisor in range(1, n):        if not n % divisor:            sum += divisor    if sum == n:        print(n, "is a perfect number")        counter1+=1    elif(sum>n):        counter2+=1    elif(sum<n):        counter3+=1    print(counter2,"abundant numbers")print(counter3,"deficient numbers")`
john727377

Posts: 4
Joined: Tue Feb 04, 2014 3:42 am