Program to Print Perfect Numbers in a given range of numbers.
Perfect number, a positive integer that is equal to the sum of its proper divisors. The smallest perfect number is 6, which is the sum of 1, 2, and 3. Other perfect numbers are 28, 496, and 8,128.
def perfect_Number(n): #user-defined function if n < 1: return False perfect_sum = 0 for i in range(1,n): if n%i==0: perfect_sum += i return perfect_sum == n # take inputs min_value = int(input()) max_value = int(input()) # calling function and print perfect numbers print('Perfect numbers from %d to %d are:' %(min_value, max_value)) for i in range(min_value, max_value+1): if perfect_Number(i): print(i, end=', ')