Computer Science, asked by ashwinkhati07, 7 months ago

write a program to enter a number and check if it is a perfect number or not.

Answers

Answered by Equestriadash
9

n = int(input("Enter a number: "))

s = 0

for i in range(1, n):

   if n%i == 0:

       s = s + i

if s == n:

   print(n, "is a perfect number.")

elif s != n:

   print(n, "isn't a perfect number.")

A number is called perfect if its divisors add up to the number itself.

  • User inputs a number.
  • Numbers from 1 to n is taken as the range.
  • If the number is divisible by each value of i, it gets added up.
  • If the final sum is equivalent to the number given, it is a perfect number.
Similar questions