Saved Bookmarks
| 1. |
Can someone help me write a Python program to accept a number and check if it's perfect using 'while' loop? |
|
Answer» 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. |
|