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.

9th Nov 2020, 9:44 AM
Dark Knight
Dark Knight - avatar
6 Respuestas
+ 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
9th Nov 2020, 10:49 AM
Rik Wittkopp
Rik Wittkopp - avatar
+ 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
9th Nov 2020, 11:00 AM
Rik Wittkopp
Rik Wittkopp - avatar
+ 2
Please define a Perfect Number.
9th Nov 2020, 10:34 AM
Rik Wittkopp
Rik Wittkopp - avatar
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)
9th Nov 2020, 9:45 AM
Dark Knight
Dark Knight - avatar
0
Here is my attempt pls add return function thank you.
9th Nov 2020, 9:45 AM
Dark Knight
Dark Knight - avatar
0
Can u pls edit it i am not sure bro
9th Nov 2020, 10:41 AM
Dark Knight
Dark Knight - avatar