write a program to enter a number and check if it is a perfect number or not.
Answers
Answered by
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
English,
3 months ago
Computer Science,
3 months ago
Computer Science,
3 months ago
Physics,
7 months ago
Accountancy,
11 months ago
English,
11 months ago