Can someone help me write a Python program to accept a number and check if it's perfect using 'while' loop?
Answers
Answered by
1
Answer:
def isPerfect( n ):
# To store sum of divisors
sum = 1
# Find all divisors and add them
i = 2
while i * i <= n:
if n % i == 0:
sum = sum + i + n/i
i += 1
# If sum of divisors is equal to
# n, then n is a perfect number
return (True if sum == n and n!=1 else False)
input = int(input("Enter a number... "))
if isPerfect(input):
print("It is a Perfect Number")
else:
print("It is not a perfect number")
HOPE IT HELPS U. PLS MARK MY ANSWER AS BRAINLIEST.
Similar questions
Math,
3 months ago
Science,
3 months ago
English,
7 months ago
Accountancy,
7 months ago
Business Studies,
11 months ago
Social Sciences,
11 months ago
Physics,
11 months ago