0
Write a program to check weather a given number is perfect or not.
Pls edit my program and add return function at it as i am unable to do so.
6 Respostas
+ 3
Is this the task description of a perfect number that you are trying to achieve?
In number theory, a perfect number is a positive integer that is equal to the sum of its positive divisors, excluding the number itself. For instance, 6 has divisors 1, 2 and 3, and 1 + 2 + 3 = 6, so 6 is a perfect number
+ 3
I have attached a sample of a code for Perfect Number, but you must turn it into a function.
The logic is there for you.
num = int(input())
factors = []
for i in range(1,num):
if num%i ==0:
factors.append(i)
print(f'{num} is a perfect number? -> {num == sum(factors)}')
Good luck
+ 2
Please define a Perfect Number.
0
def if_perfect_number(n):
i=2
test=1
while i<n:
if n%i==0:
test+=i
i+=1
if test==n:
print (n,'is perfect no')
else:
print (n,'is not perfect no')
a=int(input())
if_perfect_number(a)
0
Here is my attempt pls add return function thank you.
0
Can u pls edit it i am not sure bro