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 :
if sum < n:
print("the abundant are" ,abd)
print("the deficient are",defc)
Just hints this time...
Look carefully at where abd
are defined. How often are they initialized to 0?
Check your indentation. When are abd
incremented? Indentation is important.
Use more descriptive variable names.
Use space around operators. adb += 1
is easier to read.