In this example, you will learn to check whether number is perfect number or not based on user input.
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.
#Python Program to Check a Number is a Perfect Number or Not num = int(input("Enter a number :: ")) sumOfFactors = 0 #Calculating the sum of Factors for i in range(1,num): if num%i == 0: sumOfFactors += i; if sumOfFactors == num: print(num ," is Perfect Number") else: print(num ,"is not a Perfect Number")
Enter a number :: 10 10 is not a Perfect Number
Ask anything about this examples